diff --git a/Apple/wgpu_in_App.xcodeproj/project.xcworkspace/xcuserdata/LiJinlei.xcuserdatad/UserInterfaceState.xcuserstate b/Apple/wgpu_in_App.xcodeproj/project.xcworkspace/xcuserdata/LiJinlei.xcuserdatad/UserInterfaceState.xcuserstate index c4a62af..afd3326 100644 Binary files a/Apple/wgpu_in_App.xcodeproj/project.xcworkspace/xcuserdata/LiJinlei.xcuserdatad/UserInterfaceState.xcuserstate and b/Apple/wgpu_in_App.xcodeproj/project.xcworkspace/xcuserdata/LiJinlei.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Cargo.lock b/Cargo.lock index 6820ba2..24f47af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,12 +150,12 @@ dependencies = [ [[package]] name = "app-surface" -version = "1.1.0" +version = "1.2.0" dependencies = [ "android_logger", "ash", "cfg-if", - "core-graphics", + "core-graphics 0.24.0", "env_logger", "glam", "jni", @@ -213,18 +213,18 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bit-set" -version = "0.6.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0481a0e032742109b1133a095184ee93d88f3dc9e0d28a5d033dc77a073f44f" +checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" dependencies = [ "bit-vec", ] [[package]] name = "bit-vec" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c54ff287cfc0a34f38a6b832ea1bd8e448a330b3e40a50859e6488bee07f22" +checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" [[package]] name = "bitflags" @@ -261,9 +261,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.16.3" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "102087e286b4677862ea56cf8fc58bb2cdfa8725c40ffb80fe3a008eb7f2fc83" +checksum = "8334215b81e418a0a7bdb8ef0849474f40bb10c8b71f1c4ed315cff49f32494d" dependencies = [ "bytemuck_derive", ] @@ -276,7 +276,7 @@ checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn", ] [[package]] @@ -293,9 +293,9 @@ checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "calloop" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fba7adb4dd5aa98e5553510223000e7148f621165ec5f9acd7113f6ca4995298" +checksum = "b99da2f8558ca23c71f4fd15dc57c906239752dd27ff3c00a1d56b685b7cbfec" dependencies = [ "bitflags 2.6.0", "log", @@ -307,9 +307,9 @@ dependencies = [ [[package]] name = "calloop-wayland-source" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f0ea9b9476c7fad82841a8dbb380e2eae480c21910feba80725b46931ed8f02" +checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20" dependencies = [ "calloop", "rustix", @@ -405,7 +405,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.72", + "syn", ] [[package]] @@ -430,37 +430,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" -[[package]] -name = "com" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e17887fd17353b65b1b2ef1c526c83e26cd72e74f598a8dc1bee13a48f3d9f6" -dependencies = [ - "com_macros", -] - -[[package]] -name = "com_macros" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d375883580a668c7481ea6631fc1a8863e33cc335bf56bfad8d7e6d4b04b13a5" -dependencies = [ - "com_macros_support", - "proc-macro2", - "syn 1.0.109", -] - -[[package]] -name = "com_macros_support" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad899a1087a9296d5644792d7cb72b8e34c1bec8e7d4fbc002230169a6e8710c" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "combine" version = "4.6.7" @@ -490,11 +459,21 @@ dependencies = [ "libc", ] +[[package]] +name = "core-foundation" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "core-graphics" @@ -503,8 +482,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" dependencies = [ "bitflags 1.3.2", - "core-foundation", - "core-graphics-types", + "core-foundation 0.9.4", + "core-graphics-types 0.1.3", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa95a34622365fa5bbf40b20b75dba8dfa8c94c734aea8ac9a5ca38af14316f1" +dependencies = [ + "bitflags 2.6.0", + "core-foundation 0.10.0", + "core-graphics-types 0.2.0", "foreign-types", "libc", ] @@ -516,7 +508,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb" +dependencies = [ + "bitflags 2.6.0", + "core-foundation 0.10.0", "libc", ] @@ -538,17 +541,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" -[[package]] -name = "d3d12" -version = "22.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdbd1f579714e3c809ebd822c81ef148b1ceaeb3d535352afc73fd0c4c6a0017" -dependencies = [ - "bitflags 2.6.0", - "libloading", - "winapi", -] - [[package]] name = "dirs" version = "4.0.0" @@ -674,7 +666,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn", ] [[package]] @@ -728,9 +720,9 @@ dependencies = [ [[package]] name = "glam" -version = "0.28.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "779ae4bf7e8421cf91c0b3b64e7e8b40b862fba4d393f59150042de7c4965a94" +checksum = "480c9417a5dc586fc0c0cb67891170e59cc11e9dc79ba1c11ddd2c56ca3f3b90" [[package]] name = "glob" @@ -740,9 +732,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "glow" -version = "0.13.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd348e04c43b32574f2de31c8bb397d96c9fcfa1371bd4ca6d8bdc464ab121b1" +checksum = "d51fa363f025f5c111e03f13eda21162faeacb6911fe8caa0c0349f9cf0c4483" dependencies = [ "js-sys", "slotmap", @@ -780,14 +772,13 @@ dependencies = [ [[package]] name = "gpu-allocator" -version = "0.26.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdd4240fc91d3433d5e5b0fc5b67672d771850dc19bbee03c1381e19322803d7" +checksum = "c151a2a5ef800297b4e79efa4f4bec035c5f51d5ae587287c9b952bdf734cacd" dependencies = [ "log", "presser", "thiserror", - "winapi", "windows", ] @@ -821,21 +812,6 @@ dependencies = [ "allocator-api2", ] -[[package]] -name = "hassle-rs" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af2a7e73e1f34c48da31fb668a907f250794837e08faa144fd24f0b8b741e890" -dependencies = [ - "bitflags 2.6.0", - "com", - "libc", - "libloading", - "thiserror", - "widestring", - "winapi", -] - [[package]] name = "heck" version = "0.5.0" @@ -915,7 +891,7 @@ checksum = "9027f7e19a424f3d3b923ceac9a9ed5bbdd531d014c58ab37ee507793e8942f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn", ] [[package]] @@ -929,9 +905,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" dependencies = [ "wasm-bindgen", ] @@ -1059,7 +1035,7 @@ checksum = "7ecfd3296f8c56b7c1f6fbac3c71cefa9d78ce009850c45000015f206dc7fa21" dependencies = [ "bitflags 2.6.0", "block", - "core-graphics-types", + "core-graphics-types 0.1.3", "foreign-types", "log", "objc", @@ -1068,9 +1044,9 @@ dependencies = [ [[package]] name = "naga" -version = "22.1.0" +version = "23.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bd5a652b6faf21496f2cfd88fc49989c8db0825d1f6746b1a71a6ede24a63ad" +checksum = "3d5941e45a15b53aad4375eedf02033adb7a28931eedc31117faffa52e6a857e" dependencies = [ "arrayvec", "bit-set", @@ -1178,7 +1154,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.72", + "syn", ] [[package]] @@ -1395,9 +1371,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "orbclient" @@ -1469,7 +1445,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn", ] [[package]] @@ -1740,9 +1716,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sctk-adwaita" -version = "0.9.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7555fcb4f753d095d734fdefebb0ad8c98478a21db500492d87c55913d3b0086" +checksum = "b6277f0217056f77f1d8f49f2950ac6c278c0d607c45f5ee99328d792ede24ec" dependencies = [ "ab_glyph", "log", @@ -1768,7 +1744,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn", ] [[package]] @@ -1797,9 +1773,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smithay-client-toolkit" -version = "0.18.1" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "922fd3eeab3bd820d76537ce8f582b1cf951eceb5475c28500c7457d9d17f53a" +checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016" dependencies = [ "bitflags 2.6.0", "calloop", @@ -1856,17 +1832,6 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.72" @@ -1889,22 +1854,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn", ] [[package]] @@ -2000,9 +1965,9 @@ checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "unicode-xid" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "utf8parse" @@ -2040,34 +2005,35 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.72", + "syn", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.42" +version = "0.4.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" dependencies = [ "cfg-if", "js-sys", @@ -2077,9 +2043,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2087,22 +2053,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "wayland-backend" @@ -2154,9 +2120,9 @@ dependencies = [ [[package]] name = "wayland-protocols" -version = "0.31.2" +version = "0.32.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" +checksum = "62989625a776e827cc0f15d41444a3cea5205b963c3a25be48ae1b52d6b4daaa" dependencies = [ "bitflags 2.6.0", "wayland-backend", @@ -2166,9 +2132,9 @@ dependencies = [ [[package]] name = "wayland-protocols-plasma" -version = "0.2.0" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479" +checksum = "f79f2d57c7fcc6ab4d602adba364bf59a5c24de57bd194486bf9b8360e06bfc4" dependencies = [ "bitflags 2.6.0", "wayland-backend", @@ -2179,9 +2145,9 @@ dependencies = [ [[package]] name = "wayland-protocols-wlr" -version = "0.2.0" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" +checksum = "fd993de54a40a40fbe5601d9f1fbcaef0aebcc5fda447d7dc8f6dcbaae4f8953" dependencies = [ "bitflags 2.6.0", "wayland-backend", @@ -2215,9 +2181,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.69" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" dependencies = [ "js-sys", "wasm-bindgen", @@ -2235,9 +2201,9 @@ dependencies = [ [[package]] name = "wgpu" -version = "22.1.0" +version = "23.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d1c4ba43f80542cf63a0a6ed3134629ae73e8ab51e4b765a67f3aa062eb433" +checksum = "76ab52f2d3d18b70d5ab8dd270a1cff3ebe6dbe4a7d13c1cc2557138a9777fdc" dependencies = [ "arrayvec", "cfg_aliases 0.1.1", @@ -2260,9 +2226,9 @@ dependencies = [ [[package]] name = "wgpu-core" -version = "22.1.0" +version = "23.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0348c840d1051b8e86c3bcd31206080c5e71e5933dabd79be1ce732b0b2f089a" +checksum = "0e0c68e7b6322a03ee5b83fcd92caeac5c2a932f6457818179f4652ad2a9c065" dependencies = [ "arrayvec", "bit-vec", @@ -2285,9 +2251,9 @@ dependencies = [ [[package]] name = "wgpu-hal" -version = "22.0.0" +version = "23.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6bbf4b4de8b2a83c0401d9e5ae0080a2792055f25859a02bf9be97952bbed4f" +checksum = "de6e7266b869de56c7e3ed72a954899f71d14fec6cc81c102b7530b92947601b" dependencies = [ "android_system_properties", "arrayvec", @@ -2295,15 +2261,14 @@ dependencies = [ "bit-set", "bitflags 2.6.0", "block", + "bytemuck", "cfg_aliases 0.1.1", - "core-graphics-types", - "d3d12", + "core-graphics-types 0.1.3", "glow", "glutin_wgl_sys", "gpu-alloc", "gpu-allocator", "gpu-descriptor", - "hassle-rs", "js-sys", "khronos-egl", "libc", @@ -2325,16 +2290,18 @@ dependencies = [ "wasm-bindgen", "web-sys", "wgpu-types", - "winapi", + "windows", + "windows-core", ] [[package]] name = "wgpu-in-app" -version = "1.1.0" +version = "1.2.0" dependencies = [ "android_logger", "app-surface", "bytemuck", + "cfg-if", "env_logger", "glam", "jni", @@ -2355,9 +2322,9 @@ dependencies = [ [[package]] name = "wgpu-types" -version = "22.0.0" +version = "23.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc9d91f0e2c4b51434dfa6db77846f2793149d8e73f800fa2e41f52b8eac3c5d" +checksum = "610f6ff27778148c31093f3b03abc4840f9636d58d597ca2f5977433acfe0068" dependencies = [ "bitflags 2.6.0", "js-sys", @@ -2376,12 +2343,6 @@ dependencies = [ "rustix", ] -[[package]] -name = "widestring" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" - [[package]] name = "winapi" version = "0.3.9" @@ -2415,9 +2376,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.52.0" +version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" dependencies = [ "windows-core", "windows-targets 0.52.6", @@ -2425,10 +2386,55 @@ dependencies = [ [[package]] name = "windows-core" -version = "0.52.0" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ + "windows-result", "windows-targets 0.52.6", ] @@ -2639,9 +2645,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winit" -version = "0.30.2" +version = "0.30.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dc930d6cfbf53c4fe0b95689cdc2e17b8658c3f4214b9953298ccb5a1a15c90" +checksum = "0be9e76a1f1077e04a411f0b989cbd3c93339e1771cb41e71ac4aee95bfd2c67" dependencies = [ "ahash", "android-activity", @@ -2652,8 +2658,8 @@ dependencies = [ "calloop", "cfg_aliases 0.2.1", "concurrent-queue", - "core-foundation", - "core-graphics", + "core-foundation 0.9.4", + "core-graphics 0.23.2", "cursor-icon", "dpi", "js-sys", @@ -2779,5 +2785,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn", ] diff --git a/Cargo.toml b/Cargo.toml index 6ea837a..12186ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,17 +4,17 @@ members = ["wgpu-in-app", "app-surface", "cargo-so"] default-members = ["wgpu-in-app"] [workspace.dependencies] -bytemuck = { version = "1.16", features = ["derive"] } +bytemuck = { version = "1.19", features = ["derive"] } cfg-if = "1.0" -glam = "0.28" +glam = "0.29" log = "0.4" noise = { version = "0.8", default-features = false } pollster = "0.3" rand = "0.7.2" -wgpu = "22.1" +wgpu = "23" # wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "445fa6019b47079c9d336881dbee1c3be3ed4c38" } # wgpu = { git = "https://github.com/jinleili/wgpu", branch="visionOS" } -winit = { version = "=0.30.2" } +winit = { version = "=0.30.5" } web-time = "1" raw-window-handle = "0.6" env_logger = "0.11" @@ -22,7 +22,7 @@ env_logger = "0.11" # macOS, iOS libc = "0.2" objc = "0.2.7" -core-graphics = "0.23.1" +core-graphics = "0.24" # android target android_logger = "0.14" @@ -32,7 +32,7 @@ ndk-sys = "0.6" ash = "0.38" # wasm target -web-sys = "0.3.69" -wasm-bindgen = "0.2.87" -js-sys = "0.3.69" -wasm-bindgen-futures = "0.4.42" +web-sys = "0.3.72" +wasm-bindgen = "0.2.95" +js-sys = "0.3.72" +wasm-bindgen-futures = "0.4.45" diff --git a/app-surface/Cargo.toml b/app-surface/Cargo.toml index e2ac488..0c760b4 100644 --- a/app-surface/Cargo.toml +++ b/app-surface/Cargo.toml @@ -3,7 +3,7 @@ name = "app-surface" authors = ["jinleili"] description = "Integrate wgpu into your existing iOS and Android apps." edition = "2021" -version = "1.1.0" +version = "1.2.0" rust-version = "1.76" repository = "https://github.com/jinleili/wgpu-in-app" keywords = ["android", "SurfaceView", "ios", "macos", "wgpu"] diff --git a/app-surface/src/android.rs b/app-surface/src/android.rs index f7e0f12..e48a01b 100644 --- a/app-surface/src/android.rs +++ b/app-surface/src/android.rs @@ -10,8 +10,7 @@ use std::sync::{Arc, Mutex}; pub struct AppSurface { pub native_window: Arc, pub scale_factor: f32, - pub sdq: crate::SurfaceDeviceQueue, - pub instance: wgpu::Instance, + pub ctx: crate::IASDQContext, pub callback_to_app: Option, } @@ -23,38 +22,22 @@ impl AppSurface { backends, ..Default::default() }); + let handle: Box = Box::new(native_window.clone()); let surface = instance .create_surface(wgpu::SurfaceTarget::Window(handle)) .unwrap(); - let (adapter, device, queue) = - pollster::block_on(crate::request_device(&instance, &surface)); - - let caps = surface.get_capabilities(&adapter); - let config = wgpu::SurfaceConfiguration { - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format: wgpu::TextureFormat::Rgba8UnormSrgb, - width: native_window.get_width(), - height: native_window.get_height(), - present_mode: wgpu::PresentMode::Fifo, - alpha_mode: caps.alpha_modes[0], - view_formats: vec![], - desired_maximum_frame_latency: 2, - }; - surface.configure(&device, &config); + let ctx = pollster::block_on(crate::create_iasdq_context( + instance, + surface, + (native_window.get_width(), native_window.get_height()), + )); Self { native_window, scale_factor: 1.0, - sdq: crate::SurfaceDeviceQueue { - surface: Arc::new(surface), - config, - adapter: Arc::new(adapter), - device: Arc::new(device), - queue: Arc::new(queue), - }, - instance, + ctx, callback_to_app: None, } } diff --git a/app-surface/src/app_surface.rs b/app-surface/src/app_surface.rs index 832ea61..0977814 100644 --- a/app-surface/src/app_surface.rs +++ b/app-surface/src/app_surface.rs @@ -6,8 +6,7 @@ pub struct AppSurface { pub is_offscreen_canvas: bool, pub scale_factor: f32, pub maximum_frames: i32, - pub instance: Arc, - pub sdq: crate::SurfaceDeviceQueue, + pub ctx: crate::IASDQContext, pub callback_to_app: Option, pub temporary_directory: &'static str, pub library_directory: &'static str, @@ -107,65 +106,14 @@ impl AppSurface { } }; - let (adapter, device, queue) = crate::request_device(&instance, &surface).await; - let caps = surface.get_capabilities(&adapter); - - let modes = caps.alpha_modes; - let alpha_mode = if modes.contains(&wgpu::CompositeAlphaMode::PreMultiplied) { - // wasm can only support this alpha mode - wgpu::CompositeAlphaMode::PreMultiplied - } else if modes.contains(&wgpu::CompositeAlphaMode::PostMultiplied) { - // Metal alpha mode - wgpu::CompositeAlphaMode::PostMultiplied - } else if modes.contains(&wgpu::CompositeAlphaMode::Inherit) { - // Vulkan on Android - wgpu::CompositeAlphaMode::Inherit - } else { - modes[0] - }; - let prefered = caps.formats[0]; - let format = if cfg!(all(target_arch = "wasm32", not(feature = "webgl"))) { - // Chrome WebGPU doesn't support sRGB: - // unsupported swap chain format "xxxx8unorm-srgb" - prefered.remove_srgb_suffix() - } else { - prefered - }; - let view_formats = if cfg!(feature = "webgl") { - // panicked at 'Error in Surface::configure: Validation Error - // Caused by: - // Downlevel flags DownlevelFlags(SURFACE_VIEW_FORMATS) are required but not supported on the device. - vec![] - } else { - vec![format.add_srgb_suffix(), format.remove_srgb_suffix()] - }; - - let physical = view_setting.physical_size; - let config = wgpu::SurfaceConfiguration { - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format, - width: physical.0, - height: physical.1, - present_mode: wgpu::PresentMode::Fifo, - alpha_mode, - view_formats, - desired_maximum_frame_latency: 2, - }; - surface.configure(&device, &config); + let ctx = crate::create_iasdq_context(instance, surface, view_setting.physical_size).await; AppSurface { view: Some(view), is_offscreen_canvas, scale_factor, maximum_frames: 60, - instance: Arc::new(instance), - sdq: crate::SurfaceDeviceQueue { - surface: Arc::new(surface), - config, - adapter: Arc::new(adapter), - device: Arc::new(device), - queue: Arc::new(queue), - }, + ctx, callback_to_app: None, temporary_directory: "", library_directory: "", diff --git a/app-surface/src/ios.rs b/app-surface/src/ios.rs index dd24aa5..a177b4e 100644 --- a/app-surface/src/ios.rs +++ b/app-surface/src/ios.rs @@ -20,7 +20,7 @@ pub struct IOSViewObj { pub struct AppSurface { pub view: *mut Object, pub scale_factor: f32, - pub sdq: crate::SurfaceDeviceQueue, + pub ctx: crate::IASDQContext, pub maximum_frames: i32, pub callback_to_app: Option, pub temporary_directory: &'static str, @@ -52,34 +52,13 @@ impl AppSurface { )) .expect("Surface creation failed") }; - let (adapter, device, queue) = - pollster::block_on(crate::request_device(&instance, &surface)); - let caps = surface.get_capabilities(&adapter); - let config = wgpu::SurfaceConfiguration { - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - // CAMatalLayer's pixel format default value is MTLPixelFormatBGRA8Unorm. - // https://developer.apple.com/documentation/quartzcore/cametallayer/1478155-pixelformat?language=objc - // format: wgpu::TextureFormat::Bgra8Unorm, - // format: surface.get_supported_formats(&adapter)[0], - format: caps.formats[0], - width: physical.0, - height: physical.1, - present_mode: wgpu::PresentMode::Fifo, - alpha_mode: wgpu::CompositeAlphaMode::PostMultiplied, - view_formats: vec![], - desired_maximum_frame_latency: 2, - }; - surface.configure(&device, &config); + + let ctx = pollster::block_on(crate::create_iasdq_context(instance, surface, physical)); + AppSurface { view: obj.view, scale_factor, - sdq: crate::SurfaceDeviceQueue { - surface: Arc::new(surface), - config, - adapter: Arc::new(adapter), - device: Arc::new(device), - queue: Arc::new(queue), - }, + ctx, callback_to_app: Some(obj.callback_to_swift), maximum_frames: obj.maximum_frames, temporary_directory: "", @@ -98,18 +77,8 @@ impl AppSurface { fn get_scale_factor(obj: *mut Object) -> f32 { let mut _scale_factor: CGFloat = 1.0; - #[cfg(target_os = "macos")] - unsafe { - let window: *mut Object = msg_send![obj, window]; - if !window.is_null() { - _scale_factor = msg_send![window, backingScaleFactor]; - } - }; - #[cfg(target_os = "ios")] - { - _scale_factor = unsafe { msg_send![obj, contentScaleFactor] }; - } + _scale_factor = unsafe { msg_send![obj, contentScaleFactor] }; _scale_factor as f32 } diff --git a/app-surface/src/lib.rs b/app-surface/src/lib.rs index a738bb7..f75dc9d 100644 --- a/app-surface/src/lib.rs +++ b/app-surface/src/lib.rs @@ -17,7 +17,8 @@ pub struct ViewSize { pub height: u32, } -pub struct SurfaceDeviceQueue { +pub struct IASDQContext { + pub instance: Arc, pub surface: Arc>, pub config: wgpu::SurfaceConfiguration, pub adapter: Arc, @@ -25,7 +26,7 @@ pub struct SurfaceDeviceQueue { pub queue: Arc, } -impl SurfaceDeviceQueue { +impl IASDQContext { pub fn update_config_format(&mut self, format: wgpu::TextureFormat) { self.config.format = format; if cfg!(feature = "webgl") { @@ -38,9 +39,9 @@ impl SurfaceDeviceQueue { } impl Deref for AppSurface { - type Target = SurfaceDeviceQueue; + type Target = IASDQContext; fn deref(&self) -> &Self::Target { - &self.sdq + &self.ctx } } @@ -103,8 +104,8 @@ impl SurfaceFrame for AppSurface { fn resize_surface(&mut self) { let size = self.get_view_size(); - self.sdq.config.width = size.0; - self.sdq.config.height = size.1; + self.ctx.config.width = size.0; + self.ctx.config.height = size.1; self.surface.configure(&self.device, &self.config); } @@ -131,7 +132,57 @@ impl SurfaceFrame for AppSurface { } } -#[allow(unused)] +async fn create_iasdq_context( + instance: Instance, + surface: Surface<'static>, + physical_size: (u32, u32), +) -> IASDQContext { + let (adapter, device, queue) = crate::request_device(&instance, &surface).await; + + let caps = surface.get_capabilities(&adapter); + let prefered = caps.formats[0]; + + let format = if cfg!(all(target_arch = "wasm32", not(feature = "webgl"))) { + // Chrome WebGPU doesn't support sRGB: + // unsupported swap chain format "xxxx8unorm-srgb" + prefered.remove_srgb_suffix() + } else { + prefered + }; + let view_formats = if cfg!(feature = "webgl") { + // panicked at 'Error in Surface::configure: Validation Error + // Caused by: + // Downlevel flags DownlevelFlags(SURFACE_VIEW_FORMATS) are required but not supported on the device. + vec![] + } else { + if format.is_srgb() { + // HarmonyOS 不支持 view_formats 格式 + // format 的值与 view_formats 的值一致时,configure 内部会自动忽略 view_formats 的值 + vec![format] + } else { + vec![format.add_srgb_suffix()] + } + }; + + let mut config = surface + .get_default_config(&adapter, physical_size.0, physical_size.1) + .expect("Surface isn't supported by the adapter."); + + config.view_formats = view_formats; + config.format = format; + + surface.configure(&device, &config); + + IASDQContext { + instance: Arc::new(instance), + surface: Arc::new(surface), + config, + adapter: Arc::new(adapter), + device: Arc::new(device), + queue: Arc::new(queue), + } +} + async fn request_device( instance: &Instance, surface: &Surface<'static>, @@ -145,14 +196,17 @@ async fn request_device( }) .await .expect("No suitable GPU adapters found on the system!"); + let adapter_info = adapter.get_info(); println!("Using {} ({:?})", adapter_info.name, adapter_info.backend); + let base_dir = std::env::var("CARGO_MANIFEST_DIR"); let _trace_path = if let Ok(base_dir) = base_dir { Some(std::path::PathBuf::from(&base_dir).join("WGPU_TRACE_ERROR")) } else { None }; + let res = adapter .request_device( &wgpu::DeviceDescriptor { @@ -164,6 +218,7 @@ async fn request_device( None, ) .await; + match res { Err(err) => { panic!("request_device failed: {err:?}"); diff --git a/wgpu-in-app/Cargo.toml b/wgpu-in-app/Cargo.toml index 0a3b558..8fb88db 100644 --- a/wgpu-in-app/Cargo.toml +++ b/wgpu-in-app/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "wgpu-in-app" authors = ["jinleili"] -version = "1.1.0" +version = "1.2.0" edition = "2021" rust-version = "1.76" @@ -19,18 +19,19 @@ package = "app-surface" [dependencies] bytemuck.workspace = true +cfg-if.workspace = true glam.workspace = true log.workspace = true noise.workspace = true pollster.workspace = true rand.workspace = true wgpu.workspace = true +env_logger.workspace = true [target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))'.dependencies] winit.workspace = true [target.'cfg(target_os = "ios")'.dependencies] -env_logger.workspace = true libc.workspace = true [target.'cfg(target_os = "android")'.dependencies] diff --git a/wgpu-in-app/src/desktop.rs b/wgpu-in-app/src/desktop.rs index ea64eb2..d6d23cf 100644 --- a/wgpu-in-app/src/desktop.rs +++ b/wgpu-in-app/src/desktop.rs @@ -1,15 +1,15 @@ use std::thread; +use crate::WgpuCanvas; use app_surface::AppSurface; use std::sync::Arc; use std::time; -use crate::WgpuCanvas; use winit::{ application::ApplicationHandler, event::{ElementState, KeyEvent, StartCause, WindowEvent}, event_loop::{ActiveEventLoop, ControlFlow, EventLoop}, - keyboard::{Key, KeyCode, NamedKey, PhysicalKey}, + keyboard::{KeyCode, PhysicalKey}, window::{Window, WindowId}, }; diff --git a/wgpu-in-app/src/examples/boids.rs b/wgpu-in-app/src/examples/boids.rs index 1410f8c..9563dfe 100644 --- a/wgpu-in-app/src/examples/boids.rs +++ b/wgpu-in-app/src/examples/boids.rs @@ -132,7 +132,7 @@ impl Boids { layout: Some(&render_pipeline_layout), vertex: wgpu::VertexState { module: &draw_shader, - entry_point: "main_vs", + entry_point: Some("main_vs"), compilation_options: Default::default(), buffers: &[ wgpu::VertexBufferLayout { @@ -149,7 +149,7 @@ impl Boids { }, fragment: Some(wgpu::FragmentState { module: &draw_shader, - entry_point: "main_fs", + entry_point: Some("main_fs"), compilation_options: Default::default(), targets: &[Some(config.format.into())], }), @@ -165,7 +165,7 @@ impl Boids { label: Some("Compute pipeline"), layout: Some(&compute_pipeline_layout), module: &compute_shader, - entry_point: "main", + entry_point: Some("main"), compilation_options: Default::default(), cache: None, }); diff --git a/wgpu-in-app/src/examples/cube.rs b/wgpu-in-app/src/examples/cube.rs index b46d47c..d3c53f6 100644 --- a/wgpu-in-app/src/examples/cube.rs +++ b/wgpu-in-app/src/examples/cube.rs @@ -3,7 +3,7 @@ use super::Example; use app_surface::{AppSurface, SurfaceFrame}; use bytemuck::{Pod, Zeroable}; -use std::{borrow::Cow, future::Future, mem, pin::Pin, task}; +use std::{future::Future, pin::Pin, task}; use wgpu::util::DeviceExt; #[repr(C)] @@ -114,9 +114,10 @@ pub struct Cube { impl Cube { pub fn new(app_surface: &AppSurface) -> Self { let config = &app_surface.config; + let queue = &app_surface.queue; let device = &app_surface.device; // Create the vertex and index buffers - let vertex_size = mem::size_of::(); + let vertex_size = size_of::(); let (vertex_data, index_data) = create_vertices(); let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { @@ -182,7 +183,7 @@ impl Cube { view_formats: &[], }); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); - app_surface.queue.write_texture( + queue.write_texture( texture.as_image_copy(), &texels, wgpu::ImageDataLayout { @@ -218,12 +219,8 @@ impl Cube { label: None, }); - let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { - label: None, - source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!( - "../../wgsl_shader/cube.wgsl" - ))), - }); + let shader = + device.create_shader_module(wgpu::include_wgsl!("../../wgsl_shader/cube.wgsl")); let vertex_buffers = [wgpu::VertexBufferLayout { array_stride: vertex_size as wgpu::BufferAddress, @@ -247,15 +244,15 @@ impl Cube { layout: Some(&pipeline_layout), vertex: wgpu::VertexState { module: &shader, - entry_point: "vs_main", + entry_point: Some("vs_main"), compilation_options: Default::default(), buffers: &vertex_buffers, }, fragment: Some(wgpu::FragmentState { module: &shader, - entry_point: "fs_main", + entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(config.format.into())], + targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState { cull_mode: Some(wgpu::Face::Back), @@ -276,16 +273,16 @@ impl Cube { layout: Some(&pipeline_layout), vertex: wgpu::VertexState { module: &shader, - entry_point: "vs_main", + entry_point: Some("vs_main"), compilation_options: Default::default(), buffers: &vertex_buffers, }, fragment: Some(wgpu::FragmentState { module: &shader, - entry_point: "fs_wire", + entry_point: Some("fs_wire"), compilation_options: Default::default(), targets: &[Some(wgpu::ColorTargetState { - format: config.format, + format: config.view_formats[0], blend: Some(wgpu::BlendState { color: wgpu::BlendComponent { operation: wgpu::BlendOperation::Add, @@ -312,7 +309,6 @@ impl Cube { } else { None }; - // Done Self { vertex_buf, diff --git a/wgpu-in-app/src/examples/hdr_image_view.rs b/wgpu-in-app/src/examples/hdr_image_view.rs index ab068a5..e499136 100644 --- a/wgpu-in-app/src/examples/hdr_image_view.rs +++ b/wgpu-in-app/src/examples/hdr_image_view.rs @@ -16,7 +16,7 @@ impl HDRImageView { let hdr_pixel_format = wgpu::TextureFormat::Rgba16Float; // let hdr_pixel_format = wgpu::TextureFormat::Rgb10a2Unorm; - app_surface.sdq.update_config_format(hdr_pixel_format); + app_surface.ctx.update_config_format(hdr_pixel_format); log::info!("update_config_format: Rgba16Float"); let device = &app_surface.device; let queue = &app_surface.queue; @@ -117,13 +117,13 @@ impl HDRImageView { layout: Some(&render_pipeline_layout), vertex: wgpu::VertexState { module: &shader_module, - entry_point: "vs_main", + entry_point: Some("vs_main"), compilation_options: Default::default(), buffers: &pipeline_vertex_buffers, }, fragment: Some(wgpu::FragmentState { module: &shader_module, - entry_point: "fs_main", + entry_point: Some("fs_main"), compilation_options: Default::default(), targets: &[Some(wgpu::ColorTargetState { format: hdr_pixel_format, diff --git a/wgpu-in-app/src/examples/msaa_line.rs b/wgpu-in-app/src/examples/msaa_line.rs index 31ee8ba..67eb39d 100644 --- a/wgpu-in-app/src/examples/msaa_line.rs +++ b/wgpu-in-app/src/examples/msaa_line.rs @@ -41,7 +41,7 @@ impl MSAALine { // Only srgb format can show real MSAA effect on metal backend. if app_surface.adapter.get_info().backend == wgpu::Backend::Metal { let msaa_format = app_surface.config.format.add_srgb_suffix(); - app_surface.sdq.update_config_format(msaa_format); + app_surface.ctx.update_config_format(msaa_format); } let config = &app_surface.config; @@ -152,7 +152,7 @@ impl MSAALine { layout: Some(pipeline_layout), vertex: wgpu::VertexState { module: shader, - entry_point: "vs_main", + entry_point: Some("vs_main"), compilation_options: Default::default(), buffers: &[wgpu::VertexBufferLayout { array_stride: std::mem::size_of::() as wgpu::BufferAddress, @@ -162,7 +162,7 @@ impl MSAALine { }, fragment: Some(wgpu::FragmentState { module: shader, - entry_point: "fs_main", + entry_point: Some("fs_main"), compilation_options: Default::default(), targets: &[Some(config.format.add_srgb_suffix().into())], }), diff --git a/wgpu-in-app/src/examples/shadow.rs b/wgpu-in-app/src/examples/shadow.rs index 9091bb4..24977e7 100644 --- a/wgpu-in-app/src/examples/shadow.rs +++ b/wgpu-in-app/src/examples/shadow.rs @@ -498,7 +498,7 @@ impl Shadow { layout: Some(&pipeline_layout), vertex: wgpu::VertexState { module: &shader, - entry_point: "vs_bake", + entry_point: Some("vs_bake"), compilation_options: Default::default(), buffers: &[vb_desc.clone()], }, @@ -628,13 +628,13 @@ impl Shadow { layout: Some(&pipeline_layout), vertex: wgpu::VertexState { module: &shader, - entry_point: "vs_main", + entry_point: Some("vs_main"), compilation_options: Default::default(), buffers: &[vb_desc], }, fragment: Some(wgpu::FragmentState { module: &shader, - entry_point: "fs_main", + entry_point: Some("fs_main"), compilation_options: Default::default(), targets: &[Some(config.format.into())], }), diff --git a/wgpu-in-app/src/examples/water.rs b/wgpu-in-app/src/examples/water.rs index 3088ff4..8f20b82 100644 --- a/wgpu-in-app/src/examples/water.rs +++ b/wgpu-in-app/src/examples/water.rs @@ -336,7 +336,7 @@ impl Water { // Vertex shader and input buffers vertex: wgpu::VertexState { module: &water_module, - entry_point: "vs_main", + entry_point: Some("vs_main"), compilation_options: Default::default(), // Layout of our vertices. This should match the structs // which are uploaded to the GPU. This should also be @@ -352,7 +352,7 @@ impl Water { // Fragment shader and output targets fragment: Some(wgpu::FragmentState { module: &water_module, - entry_point: "fs_main", + entry_point: Some("fs_main"), compilation_options: Default::default(), // Describes how the colour will be interpolated // and assigned to the output attachment. @@ -408,7 +408,7 @@ impl Water { layout: Some(&terrain_pipeline_layout), vertex: wgpu::VertexState { module: &terrain_module, - entry_point: "vs_main", + entry_point: Some("vs_main"), compilation_options: Default::default(), buffers: &[wgpu::VertexBufferLayout { array_stride: terrain_vertex_size as wgpu::BufferAddress, @@ -418,7 +418,7 @@ impl Water { }, fragment: Some(wgpu::FragmentState { module: &terrain_module, - entry_point: "fs_main", + entry_point: Some("fs_main"), compilation_options: Default::default(), targets: &[Some(config.format.into())], }), diff --git a/wgpu-in-app/src/ffi/android.rs b/wgpu-in-app/src/ffi/android.rs index 1856216..081a47d 100644 --- a/wgpu-in-app/src/ffi/android.rs +++ b/wgpu-in-app/src/ffi/android.rs @@ -1,19 +1,19 @@ use crate::wgpu_canvas::WgpuCanvas; -use android_logger::Config; use app_surface::AppSurface; use jni::objects::JClass; use jni::sys::{jint, jlong, jobject}; use jni::JNIEnv; use jni_fn::jni_fn; -use log::{info, LevelFilter}; +use log::info; #[no_mangle] #[jni_fn("name.jinleili.wgpu.RustBridge")] pub fn createWgpuCanvas(env: *mut JNIEnv, _: JClass, surface: jobject, idx: jint) -> jlong { - log_panics::init(); - android_logger::init_once(Config::default().with_max_level(LevelFilter::Error)); - let canvas = WgpuCanvas::new(AppSurface::new(env as *mut _, surface), idx); + crate::init_logger(); + + let mut canvas = WgpuCanvas::new(AppSurface::new(env as *mut _, surface), idx); info!("WgpuCanvas created!"); + Box::into_raw(Box::new(canvas)) as jlong } diff --git a/wgpu-in-app/src/lib.rs b/wgpu-in-app/src/lib.rs index 08ac035..2fdc53f 100644 --- a/wgpu-in-app/src/lib.rs +++ b/wgpu-in-app/src/lib.rs @@ -10,4 +10,49 @@ mod ffi; pub use ffi::*; #[cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))] -pub mod desktop; \ No newline at end of file +pub mod desktop; + +// Initialize logging in platform dependant ways. +fn init_logger() { + cfg_if::cfg_if! { + if #[cfg(target_arch = "wasm32")] { + // As we don't have an environment to pull logging level from, we use the query string. + let query_string = web_sys::window().unwrap().location().search().unwrap(); + let query_level: Option = parse_url_query_string(&query_string, "RUST_LOG") + .and_then(|x| x.parse().ok()); + + // We keep wgpu at Error level, as it's very noisy. + let base_level = query_level.unwrap_or(log::LevelFilter::Info); + let wgpu_level = query_level.unwrap_or(log::LevelFilter::Error); + + // On web, we use fern, as console_log doesn't have filtering on a per-module level. + fern::Dispatch::new() + .level(base_level) + .level_for("wgpu_core", wgpu_level) + .level_for("wgpu_hal", wgpu_level) + .level_for("naga", wgpu_level) + .chain(fern::Output::call(console_log::log)) + .apply() + .unwrap(); + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); + } else if #[cfg(target_os = "android")] { + // 添加 Android 平台的日志初始化 + android_logger::init_once( + android_logger::Config::default() + .with_max_level(log::LevelFilter::Info) + ); + log_panics::init(); + } else { + // parse_default_env will read the RUST_LOG environment variable and apply it on top + // of these default filters. + env_logger::builder() + .filter_level(log::LevelFilter::Info) + // We keep wgpu at Error level, as it's very noisy. + .filter_module("wgpu_core", log::LevelFilter::Info) + .filter_module("wgpu_hal", log::LevelFilter::Error) + .filter_module("naga", log::LevelFilter::Error) + .parse_default_env() + .init(); + } + } +} diff --git a/wgpu-in-app/src/wgpu_canvas.rs b/wgpu-in-app/src/wgpu_canvas.rs index 9e84034..34eb86b 100644 --- a/wgpu-in-app/src/wgpu_canvas.rs +++ b/wgpu-in-app/src/wgpu_canvas.rs @@ -10,7 +10,7 @@ pub struct WgpuCanvas { impl WgpuCanvas { pub fn new(app_surface: AppSurface, idx: i32) -> Self { let example = Box::new(Empty::new(&app_surface)); - log::info!("example created"); + let mut instance = WgpuCanvas { app_surface, example, diff --git a/wgpu-in-app/wgsl_shader/cube.wgsl b/wgpu-in-app/wgsl_shader/cube.wgsl index 96d54f6..3769394 100644 --- a/wgpu-in-app/wgsl_shader/cube.wgsl +++ b/wgpu-in-app/wgsl_shader/cube.wgsl @@ -1,23 +1,20 @@ struct VertexOutput { - @location(0) tex_coord: vec2f, - @builtin(position) position: vec4f, + @location(0) tex_coord: vec2, + @builtin(position) position: vec4, }; -struct Locals { - transform: mat4x4f -}; @group(0) @binding(0) -var r_locals: Locals; +var transform: mat4x4; @vertex fn vs_main( - @location(0) position: vec4f, - @location(1) tex_coord: vec2f, + @location(0) position: vec4, + @location(1) tex_coord: vec2, ) -> VertexOutput { var result: VertexOutput; result.tex_coord = tex_coord; - result.position = r_locals.transform * position; + result.position = transform * position; return result; } @@ -26,13 +23,13 @@ fn vs_main( var r_color: texture_2d; @fragment -fn fs_main(vertex: VertexOutput) -> @location(0) vec4f { +fn fs_main(vertex: VertexOutput) -> @location(0) vec4 { let tex = textureLoad(r_color, vec2(vertex.tex_coord * 256.0), 0); let v = f32(tex.x) / 255.0; - return vec4f(1.0 - (v * 5.0), 1.0 - (v * 15.0), 1.0 - (v * 50.0), 1.0); + return vec4(1.0 - (v * 5.0), 1.0 - (v * 15.0), 1.0 - (v * 50.0), 1.0); } @fragment -fn fs_wire(vertex: VertexOutput) -> @location(0) vec4f { - return vec4f(0.0, 0.5, 0.0, 0.5); -} +fn fs_wire(vertex: VertexOutput) -> @location(0) vec4 { + return vec4(0.0, 0.5, 0.0, 0.5); +} \ No newline at end of file