diff --git a/CHANGELOG.md b/CHANGELOG.md index 16890afc64..4b50e3700d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -175,6 +175,10 @@ By @cwfitzgerald in [#3610](https://github.com/gfx-rs/wgpu/pull/3610). - Fix metal erroring on an `array_stride` of 0. By @teoxoy in [#3538](https://github.com/gfx-rs/wgpu/pull/3538) +#### WebGPU + +- Avoid using `WasmAbi` functions for WebGPU backend. By @grovesNL in [#3657](https://github.com/gfx-rs/wgpu/pull/3657) + #### General - `copyTextureToTexture` src/dst aspects must both refer to all aspects of src/dst format. By @teoxoy in [#3431](https://github.com/gfx-rs/wgpu/pull/3431) diff --git a/Cargo.lock b/Cargo.lock index 45f017ba9a..4f02278ab9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,12 +46,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anyhow" -version = "1.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" - [[package]] name = "arrayref" version = "0.3.6" @@ -112,17 +106,6 @@ version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" -[[package]] -name = "async-trait" -version = "0.1.59" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6e93155431f3931513b243d371981bb2770112b370c82745a1d19d2f99364" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.105", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -144,32 +127,12 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base64" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" -dependencies = [ - "byteorder", - "safemem", -] - [[package]] name = "base64" version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "base64-simd" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "339abbe78e73178762e23bea9dfd08e697eb3f3301cd4be981c0f78ba5859195" -dependencies = [ - "outref", - "vsimd", -] - [[package]] name = "bit-set" version = "0.5.3" @@ -235,12 +198,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" - [[package]] name = "calloop" version = "0.10.2" @@ -254,18 +211,6 @@ dependencies = [ "vec_map", ] -[[package]] -name = "cargo-run-wasm" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc1e37cf14ef470ed74ec2a8b95e51b8623bcf6f76d24f233ebaeb209f766230" -dependencies = [ - "devserver_lib", - "pico-args", - "serde_json", - "wasm-bindgen-cli-support", -] - [[package]] name = "cc" version = "1.0.77" @@ -378,12 +323,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - [[package]] name = "core-foundation" version = "0.9.3" @@ -478,20 +417,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "cts_runner" -version = "0.1.0" -dependencies = [ - "deno_console", - "deno_core", - "deno_url", - "deno_web", - "deno_webgpu", - "deno_webidl", - "termcolor", - "tokio", -] - [[package]] name = "cty" version = "0.2.2" @@ -554,123 +479,6 @@ dependencies = [ "enum_primitive", ] -[[package]] -name = "deno_console" -version = "0.92.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55193bcb66a9a9830e1348280acbb9dd65c67d9a9a0586af9730079886408dce" -dependencies = [ - "deno_core", -] - -[[package]] -name = "deno_core" -version = "0.174.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8077367e7e7ab2f52f1bc6285af301a1a6328b984991a3ff22236ad79862fce3" -dependencies = [ - "anyhow", - "bytes", - "deno_ops", - "futures", - "indexmap", - "libc", - "log", - "once_cell", - "parking_lot 0.12.1", - "pin-project", - "serde", - "serde_json", - "serde_v8", - "smallvec", - "sourcemap", - "url", - "v8", -] - -[[package]] -name = "deno_ops" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc9d81c9e5cd9590be6043546f4565670cb6e6a7de1986fd1c354adce04eb9d4" -dependencies = [ - "once_cell", - "pmutil", - "proc-macro-crate", - "proc-macro2", - "quote", - "regex", - "syn 1.0.105", -] - -[[package]] -name = "deno_url" -version = "0.92.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "906895a8ba4a95f48c51a32947061bf82f42da8f7c8df787012503f1a6042685" -dependencies = [ - "deno_core", - "serde", - "serde_repr", - "urlpattern", -] - -[[package]] -name = "deno_web" -version = "0.123.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af75e7ff90a3f719adc074a8789da16687b9e77a97d67eb727b65fae71262637" -dependencies = [ - "async-trait", - "base64-simd", - "deno_core", - "encoding_rs", - "flate2", - "serde", - "tokio", - "uuid", -] - -[[package]] -name = "deno_webgpu" -version = "0.85.0" -dependencies = [ - "deno_core", - "raw-window-handle 0.5.2", - "serde", - "tokio", - "wgpu-core", - "wgpu-types", -] - -[[package]] -name = "deno_webidl" -version = "0.92.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "387a0cfb076580e0237ba6f1b338ee2688779c6a5e531d4a8a2a82b216917ae0" -dependencies = [ - "deno_core", -] - -[[package]] -name = "derive_more" -version = "0.99.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "rustc_version 0.4.0", - "syn 1.0.105", -] - -[[package]] -name = "devserver_lib" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb4b71acc1405be2431a93892a79a0d82ed5ba6885649ddbdfc62caa4d67b1c" - [[package]] name = "dispatch" version = "0.2.0" @@ -713,21 +521,6 @@ dependencies = [ "wio", ] -[[package]] -name = "either" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" - -[[package]] -name = "encoding_rs" -version = "0.8.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" -dependencies = [ - "cfg-if", -] - [[package]] name = "enum_primitive" version = "0.1.1" @@ -860,15 +653,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" -[[package]] -name = "form_urlencoded" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" -dependencies = [ - "percent-encoding", -] - [[package]] name = "freetype-rs" version = "0.26.0" @@ -891,58 +675,12 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "fslock" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57eafdd0c16f57161105ae1b98a1238f97645f2f588438b2949c99a2af9616bf" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "futures" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" -dependencies = [ - "futures-core", - "futures-sink", -] - [[package]] name = "futures-core" version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" -[[package]] -name = "futures-executor" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - [[package]] name = "futures-intrusive" version = "0.4.2" @@ -975,47 +713,6 @@ dependencies = [ "waker-fn", ] -[[package]] -name = "futures-macro" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.105", -] - -[[package]] -name = "futures-sink" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" - -[[package]] -name = "futures-task" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" - -[[package]] -name = "futures-util" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - [[package]] name = "getrandom" version = "0.1.16" @@ -1214,24 +911,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.1" @@ -1250,34 +929,12 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - [[package]] name = "ident_case" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" -[[package]] -name = "idna" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "if_chain" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed" - [[package]] name = "image" version = "0.24.6" @@ -1331,7 +988,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi", "io-lifetimes", "rustix", "windows-sys 0.45.0", @@ -1381,12 +1038,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - [[package]] name = "libc" version = "0.2.141" @@ -1668,16 +1319,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" -dependencies = [ - "hermit-abi 0.1.19", - "libc", -] - [[package]] name = "num_enum" version = "0.5.7" @@ -1748,12 +1389,6 @@ dependencies = [ "shared_library", ] -[[package]] -name = "outref" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4030760ffd992bef45b0ae3f10ce1aba99e33464c90d14dd7c039884963ddc7a" - [[package]] name = "parking" version = "2.0.0" @@ -1824,44 +1459,12 @@ dependencies = [ "indexmap", ] -[[package]] -name = "pico-args" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" - -[[package]] -name = "pin-project" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.105", -] - [[package]] name = "pin-project-lite" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "pkg-config" version = "0.3.26" @@ -1883,21 +1486,10 @@ dependencies = [ ] [[package]] -name = "pmutil" -version = "0.5.3" +name = "png" +version = "0.17.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3894e5d549cccbe44afecf72922f277f603cd4bb0219c8342631ef18fffbe004" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.105", -] - -[[package]] -name = "png" -version = "0.17.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d708eaf860a19b19ce538740d2b4bdeeb8337fa53f7738455e706623ad5c638" +checksum = "5d708eaf860a19b19ce538740d2b4bdeeb8337fa53f7738455e706623ad5c638" dependencies = [ "bitflags 1.3.2", "crc32fast", @@ -2070,18 +1662,11 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "300a51053b1cb55c80b7a9fde4120726ddf25ca241a1cbb926626f62fb136bff" dependencies = [ - "base64 0.13.1", + "base64", "bitflags 1.3.2", "serde", ] -[[package]] -name = "run-wasm" -version = "0.15.0" -dependencies = [ - "cargo-run-wasm", -] - [[package]] name = "rustc-demangle" version = "0.1.21" @@ -2094,24 +1679,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver 1.0.14", -] - [[package]] name = "rustix" version = "0.36.8" @@ -2141,12 +1708,6 @@ dependencies = [ "bytemuck", ] -[[package]] -name = "safemem" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" - [[package]] name = "scoped-tls" version = "1.0.1" @@ -2171,27 +1732,6 @@ dependencies = [ "tiny-skia", ] -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" version = "1.0.159" @@ -2201,15 +1741,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde_bytes" -version = "0.11.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfc50e8183eeeb6178dcb167ae34a8051d63535023ae38b5d8d12beae193d37b" -dependencies = [ - "serde", -] - [[package]] name = "serde_derive" version = "1.0.159" @@ -2227,37 +1758,11 @@ version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" dependencies = [ - "indexmap", "itoa", "ryu", "serde", ] -[[package]] -name = "serde_repr" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.105", -] - -[[package]] -name = "serde_v8" -version = "0.85.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dba78050262072324b0b1efba11db7367735251adf7ec734fd75780c598c743b" -dependencies = [ - "bytes", - "derive_more", - "serde", - "serde_bytes", - "smallvec", - "v8", -] - [[package]] name = "servo-fontconfig" version = "0.5.1" @@ -2289,15 +1794,6 @@ dependencies = [ "libc", ] -[[package]] -name = "signal-hook-registry" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" -dependencies = [ - "libc", -] - [[package]] name = "slab" version = "0.4.7" @@ -2341,32 +1837,6 @@ dependencies = [ "wayland-protocols", ] -[[package]] -name = "socket2" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "sourcemap" -version = "6.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c46fdc1838ff49cf692226f5c2b0f5b7538f556863d0eca602984714667ac6e7" -dependencies = [ - "base64 0.13.1", - "if_chain", - "lazy_static", - "regex", - "rustc_version 0.2.3", - "serde", - "serde_json", - "url", -] - [[package]] name = "spirv" version = "0.2.0+1.5.4" @@ -2411,19 +1881,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempfile" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" -dependencies = [ - "cfg-if", - "fastrand", - "redox_syscall", - "rustix", - "windows-sys 0.42.0", -] - [[package]] name = "termcolor" version = "1.2.0" @@ -2478,52 +1935,6 @@ dependencies = [ "bytemuck", ] -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" - -[[package]] -name = "tokio" -version = "1.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" -dependencies = [ - "autocfg", - "bytes", - "libc", - "memchr", - "mio", - "num_cpus", - "parking_lot 0.12.1", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.42.0", -] - -[[package]] -name = "tokio-macros" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.105", -] - [[package]] name = "toml" version = "0.5.9" @@ -2533,74 +1944,12 @@ dependencies = [ "serde", ] -[[package]] -name = "unic-char-property" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221" -dependencies = [ - "unic-char-range", -] - -[[package]] -name = "unic-char-range" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc" - -[[package]] -name = "unic-common" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" - -[[package]] -name = "unic-ucd-ident" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e230a37c0381caa9219d67cf063aa3a375ffed5bf541a452db16e744bdab6987" -dependencies = [ - "unic-char-property", - "unic-char-range", - "unic-ucd-version", -] - -[[package]] -name = "unic-ucd-version" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4" -dependencies = [ - "unic-common", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" - [[package]] name = "unicode-ident" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-segmentation" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" - [[package]] name = "unicode-width" version = "0.1.10" @@ -2613,53 +1962,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "url" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", - "serde", -] - -[[package]] -name = "urlpattern" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9bd5ff03aea02fa45b13a7980151fe45009af1980ba69f651ec367121a31609" -dependencies = [ - "derive_more", - "regex", - "serde", - "unic-ucd-ident", - "url", -] - -[[package]] -name = "uuid" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" -dependencies = [ - "getrandom 0.2.8", - "serde", -] - -[[package]] -name = "v8" -version = "0.64.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2287b485fa902172da3722d7e557e083afd63921777e0c6e5c0fba28e6d59d3" -dependencies = [ - "bitflags 1.3.2", - "fslock", - "lazy_static", - "which", -] - [[package]] name = "vec_map" version = "0.8.2" @@ -2672,44 +1974,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "vsimd" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64" - [[package]] name = "waker-fn" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" -[[package]] -name = "walrus" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb08e48cde54c05f363d984bb54ce374f49e242def9468d2e1b6c2372d291f8" -dependencies = [ - "anyhow", - "id-arena", - "leb128", - "log", - "walrus-macro", - "wasmparser 0.77.0", -] - -[[package]] -name = "walrus-macro" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a6e5bd22c71e77d60140b0bd5be56155a37e5bd14e24f5f87298040d0cc40d7" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 1.0.105", -] - [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" @@ -2747,41 +2017,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-cli-support" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d4780c659b883a19ddb7ced365db19f7f45cd182d832ee14de2b7ef52e88a9f" -dependencies = [ - "anyhow", - "base64 0.9.3", - "log", - "rustc-demangle", - "serde_json", - "tempfile", - "unicode-ident", - "walrus", - "wasm-bindgen-externref-xform", - "wasm-bindgen-multi-value-xform", - "wasm-bindgen-shared", - "wasm-bindgen-threads-xform", - "wasm-bindgen-wasm-conventions", - "wasm-bindgen-wasm-interpreter", - "wit-text", - "wit-validator", - "wit-walrus", -] - -[[package]] -name = "wasm-bindgen-externref-xform" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d154c3843bf3b635b602ad41b56f505f8f1a25f8a0133fca4bbd0918d74efdc" -dependencies = [ - "anyhow", - "walrus", -] - [[package]] name = "wasm-bindgen-futures" version = "0.4.34" @@ -2817,16 +2052,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-multi-value-xform" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c00a577fbd4be358ef8095432189b5c2e6b6e71f5081797c2032572f77d65d26" -dependencies = [ - "anyhow", - "walrus", -] - [[package]] name = "wasm-bindgen-shared" version = "0.2.84" @@ -2857,60 +2082,6 @@ dependencies = [ "quote", ] -[[package]] -name = "wasm-bindgen-threads-xform" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aa93941bae037b7b4fac4ecfc132294b828036c5990a806d0e6fd9284297d94" -dependencies = [ - "anyhow", - "walrus", - "wasm-bindgen-wasm-conventions", -] - -[[package]] -name = "wasm-bindgen-wasm-conventions" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8f5de325048d945c90600fdf66b13521f3340d85971287775c36aa99c04466b" -dependencies = [ - "anyhow", - "walrus", -] - -[[package]] -name = "wasm-bindgen-wasm-interpreter" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f695df44962e3a107436282232a2daa185b8453c16be8ddfb637cd2601f31128" -dependencies = [ - "anyhow", - "log", - "walrus", - "wasm-bindgen-wasm-conventions", -] - -[[package]] -name = "wasmparser" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a950e6a618f62147fd514ff445b2a0b53120d382751960797f85f058c7eda9b9" - -[[package]] -name = "wasmparser" -version = "0.77.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b35c86d22e720a07d954ebbed772d01180501afe7d03d464f413bb5f8914a8d6" - -[[package]] -name = "wast" -version = "21.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b1844f66a2bc8526d71690104c0e78a8e59ffa1597b7245769d174ebb91deb5" -dependencies = [ - "leb128", -] - [[package]] name = "wayland-client" version = "0.29.5" @@ -3130,17 +2301,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "which" -version = "4.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" -dependencies = [ - "either", - "libc", - "once_cell", -] - [[package]] name = "widestring" version = "1.0.2" @@ -3353,70 +2513,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "wit-parser" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f5fd97866f4b9c8e1ed57bcf9446f3d0d8ba37e2dd01c3c612c046c053b06f7" -dependencies = [ - "anyhow", - "leb128", - "wit-schema-version", -] - -[[package]] -name = "wit-schema-version" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfee4a6a4716eefa0682e7a3b836152e894a3e4f34a9d6c2c3e1c94429bfe36a" - -[[package]] -name = "wit-text" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33358e95c77d660f1c7c07f4a93c2bd89768965e844e3c50730bb4b42658df5f" -dependencies = [ - "anyhow", - "wast", - "wit-writer", -] - -[[package]] -name = "wit-validator" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c11d93d925420e7872b226c4161849c32be38385ccab026b88df99d8ddc6ba6" -dependencies = [ - "anyhow", - "wasmparser 0.59.0", - "wit-parser", - "wit-schema-version", -] - -[[package]] -name = "wit-walrus" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad559e3e4c6404b2a6a675d44129d62a3836e3b951b90112fa1c5feb852757cd" -dependencies = [ - "anyhow", - "id-arena", - "walrus", - "wit-parser", - "wit-schema-version", - "wit-writer", -] - -[[package]] -name = "wit-writer" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2ad01ba5e9cbcff799a0689e56a153776ea694cec777f605938cb9880d41a09" -dependencies = [ - "leb128", - "wit-schema-version", -] - [[package]] name = "x11-dl" version = "2.20.1" diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 028bdaebe9..d79c11f8f0 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -2235,13 +2235,15 @@ impl crate::Context for Context { } } - fn queue_submit>( + fn queue_submit>( &self, queue: &Self::QueueId, _queue_data: &Self::QueueData, command_buffers: I, ) -> (Self::SubmissionIndex, Self::SubmissionIndexData) { - let temp_command_buffers = command_buffers.collect::>(); + let temp_command_buffers = command_buffers + .map(|(i, _)| i) + .collect::>(); let global = &self.0; let index = match wgc::gfx_select!(*queue => global.queue_submit(*queue, &temp_command_buffers)) @@ -2924,9 +2926,11 @@ impl crate::Context for Context { &self, _pass: &mut Self::RenderPassId, pass_data: &mut Self::RenderPassData, - render_bundles: Box + 'a>, + render_bundles: Box< + dyn Iterator + 'a, + >, ) { - let temp_render_bundles = render_bundles.collect::>(); + let temp_render_bundles = render_bundles.map(|(i, _)| i).collect::>(); unsafe { wgpu_render_pass_execute_bundles( pass_data, diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index c373e15737..c7eb4a8b14 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -6,30 +6,27 @@ use std::{ cell::RefCell, fmt, future::Future, + marker::PhantomData, ops::Range, pin::Pin, rc::Rc, task::{self, Poll}, }; -use wasm_bindgen::{ - convert::{FromWasmAbi, IntoWasmAbi}, - prelude::*, - JsCast, -}; +use wasm_bindgen::{prelude::*, JsCast}; use crate::{ - context::{ObjectId, QueueWriteBuffer, Unused}, + context::{downcast_ref, ObjectId, QueueWriteBuffer, Unused}, UncapturedErrorHandler, }; -fn create_identified(value: T) -> Identified { +fn create_identified(value: T) -> (Identified, Sendable) { cfg_if::cfg_if! { if #[cfg(feature = "expose-ids")] { static NEXT_ID: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1); let id = NEXT_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - Identified(value, core::num::NonZeroU64::new(id).unwrap()) + (Identified(core::num::NonZeroU64::new(id).unwrap(), PhantomData), Sendable(value)) } else { - Identified(value) + (Identified(PhantomData), Sendable(value)) } } } @@ -42,42 +39,53 @@ fn create_identified(value: T) -> Identified { // type is (for now) harmless. Eventually wasm32 will support threading, and depending on how this // is integrated (or not integrated) with values like those in webgpu, this may become unsound. -impl + JsCast> From for Identified { +#[allow(unused_variables)] +impl From for Identified { fn from(object_id: ObjectId) -> Self { - let id = object_id.id().get() as u32; - // SAFETY: wasm_bindgen says an ABI representation may only be cast to a wrapper type if it was created - // using into_abi. - // - // This assumption we sadly have to assume to prevent littering the code with unsafe blocks. - let wasm = unsafe { JsValue::from_abi(id) }; - wgt::strict_assert!(wasm.is_instance_of::()); - // SAFETY: The ABI of the type must be a u32, and strict asserts ensure the right type is used. Self( - wasm.unchecked_into(), #[cfg(feature = "expose-ids")] object_id.global_id(), + PhantomData, ) } } -impl> From> for ObjectId { +#[allow(unused_variables)] +impl From> for ObjectId { fn from(identified: Identified) -> Self { - let id = core::num::NonZeroU64::new(identified.0.into_abi() as u64).unwrap(); Self::new( - id, + // TODO: the ID isn't used, so we hardcode it to 1 for now until we rework this + // API. + core::num::NonZeroU64::new(1).unwrap(), #[cfg(feature = "expose-ids")] identified.1, ) } } +#[allow(unused_variables)] +impl From<(Identified, Sendable)> for ObjectId { + fn from((id, _data): (Identified, Sendable)) -> Self { + Self::new( + // TODO: the ID isn't used, so we hardcode it to 1 for now until we rework this + // API. + core::num::NonZeroU64::new(1).unwrap(), + #[cfg(feature = "expose-ids")] + id.1, + ) + } +} + #[derive(Clone, Debug)] pub(crate) struct Sendable(T); unsafe impl Send for Sendable {} unsafe impl Sync for Sendable {} #[derive(Clone, Debug)] -pub(crate) struct Identified(T, #[cfg(feature = "expose-ids")] std::num::NonZeroU64); +pub(crate) struct Identified( + #[cfg(feature = "expose-ids")] std::num::NonZeroU64, + PhantomData, +); unsafe impl Send for Identified {} unsafe impl Sync for Identified {} @@ -457,8 +465,8 @@ fn map_texture_view_dimension( } fn map_buffer_copy_view(view: crate::ImageCopyBuffer) -> web_sys::GpuImageCopyBuffer { - let buffer = &<::BufferId>::from(view.buffer.id).0; - let mut mapped = web_sys::GpuImageCopyBuffer::new(buffer); + let buffer: &::BufferData = downcast_ref(view.buffer.data.as_ref()); + let mut mapped = web_sys::GpuImageCopyBuffer::new(&buffer.0); if let Some(bytes_per_row) = view.layout.bytes_per_row { mapped.bytes_per_row(bytes_per_row); } @@ -470,8 +478,9 @@ fn map_buffer_copy_view(view: crate::ImageCopyBuffer) -> web_sys::GpuImageCopyBu } fn map_texture_copy_view(view: crate::ImageCopyTexture) -> web_sys::GpuImageCopyTexture { - let texture = &<::TextureId>::from(view.texture.id).0; - let mut mapped = web_sys::GpuImageCopyTexture::new(texture); + let texture: &::TextureData = + downcast_ref(view.texture.data.as_ref()); + let mut mapped = web_sys::GpuImageCopyTexture::new(&texture.0); mapped.mip_level(view.mip_level); mapped.origin(&map_origin_3d(view.origin)); mapped @@ -480,8 +489,9 @@ fn map_texture_copy_view(view: crate::ImageCopyTexture) -> web_sys::GpuImageCopy fn map_tagged_texture_copy_view( view: crate::ImageCopyTextureTagged, ) -> web_sys::GpuImageCopyTextureTagged { - let texture = &<::TextureId>::from(view.texture.id).0; - let mut mapped = web_sys::GpuImageCopyTextureTagged::new(texture); + let texture: &::TextureData = + downcast_ref(view.texture.data.as_ref()); + let mut mapped = web_sys::GpuImageCopyTextureTagged::new(&texture.0); mapped.mip_level(view.mip_level); mapped.origin(&map_origin_3d(view.origin)); mapped.aspect(map_texture_aspect(view.aspect)); @@ -598,9 +608,14 @@ fn map_wgt_features(supported_features: web_sys::GpuSupportedFeatures) -> wgt::F type JsFutureResult = Result; -fn future_request_adapter(result: JsFutureResult) -> Option<(Identified, ())> { +fn future_request_adapter( + result: JsFutureResult, +) -> Option<( + Identified, + Sendable, +)> { match result.and_then(wasm_bindgen::JsCast::dyn_into) { - Ok(adapter) => Some((create_identified(adapter), ())), + Ok(adapter) => Some(create_identified(adapter)), Err(_) => None, } } @@ -610,23 +625,18 @@ fn future_request_device( ) -> Result< ( Identified, - (), + Sendable, Identified, - (), + Sendable, ), crate::RequestDeviceError, > { result .map(|js_value| { - let device_id = web_sys::GpuDevice::from(js_value); - let queue_id = device_id.queue(); + let (device_id, device_data) = create_identified(web_sys::GpuDevice::from(js_value)); + let (queue_id, queue_data) = create_identified(device_data.0.queue()); - ( - create_identified(device_id), - (), - create_identified(queue_id), - (), - ) + (device_id, device_data, queue_id, queue_data) }) .map_err(|_| crate::RequestDeviceError) } @@ -687,14 +697,26 @@ impl Context { pub fn instance_create_surface_from_canvas( &self, canvas: &web_sys::HtmlCanvasElement, - ) -> Result<::SurfaceId, crate::CreateSurfaceError> { + ) -> Result< + ( + ::SurfaceId, + ::SurfaceData, + ), + crate::CreateSurfaceError, + > { self.create_surface_from_context(canvas.get_context("webgpu")) } pub fn instance_create_surface_from_offscreen_canvas( &self, canvas: &web_sys::OffscreenCanvas, - ) -> Result<::SurfaceId, crate::CreateSurfaceError> { + ) -> Result< + ( + ::SurfaceId, + ::SurfaceData, + ), + crate::CreateSurfaceError, + > { self.create_surface_from_context(canvas.get_context("webgpu")) } @@ -705,7 +727,13 @@ impl Context { fn create_surface_from_context( &self, context_result: Result, wasm_bindgen::JsValue>, - ) -> Result<::SurfaceId, crate::CreateSurfaceError> { + ) -> Result< + ( + ::SurfaceId, + ::SurfaceData, + ), + crate::CreateSurfaceError, + > { let context: js_sys::Object = match context_result { Ok(Some(context)) => context, Ok(None) => { @@ -752,47 +780,47 @@ extern "C" { impl crate::context::Context for Context { type AdapterId = Identified; - type AdapterData = (); + type AdapterData = Sendable; type DeviceId = Identified; - type DeviceData = (); + type DeviceData = Sendable; type QueueId = Identified; - type QueueData = (); + type QueueData = Sendable; type ShaderModuleId = Identified; - type ShaderModuleData = (); + type ShaderModuleData = Sendable; type BindGroupLayoutId = Identified; - type BindGroupLayoutData = (); + type BindGroupLayoutData = Sendable; type BindGroupId = Identified; - type BindGroupData = (); + type BindGroupData = Sendable; type TextureViewId = Identified; - type TextureViewData = (); + type TextureViewData = Sendable; type SamplerId = Identified; - type SamplerData = (); + type SamplerData = Sendable; type BufferId = Identified; - type BufferData = (); + type BufferData = Sendable; type TextureId = Identified; - type TextureData = (); + type TextureData = Sendable; type QuerySetId = Identified; - type QuerySetData = (); + type QuerySetData = Sendable; type PipelineLayoutId = Identified; - type PipelineLayoutData = (); + type PipelineLayoutData = Sendable; type RenderPipelineId = Identified; - type RenderPipelineData = (); + type RenderPipelineData = Sendable; type ComputePipelineId = Identified; - type ComputePipelineData = (); + type ComputePipelineData = Sendable; type CommandEncoderId = Identified; - type CommandEncoderData = (); + type CommandEncoderData = Sendable; type ComputePassId = Identified; - type ComputePassData = (); + type ComputePassData = Sendable; type RenderPassId = Identified; - type RenderPassData = (); + type RenderPassData = Sendable; type CommandBufferId = Identified; - type CommandBufferData = (); + type CommandBufferData = Sendable; type RenderBundleEncoderId = Identified; - type RenderBundleEncoderData = (); + type RenderBundleEncoderData = Sendable; type RenderBundleId = Identified; - type RenderBundleData = (); + type RenderBundleData = Sendable; type SurfaceId = Identified; - type SurfaceData = (); + type SurfaceData = Sendable; type SurfaceOutputDetail = SurfaceOutputDetail; type SubmissionIndex = Unused; @@ -855,10 +883,7 @@ impl crate::context::Context for Context { .expect("expected to find single canvas") .into(); let canvas_element: web_sys::HtmlCanvasElement = canvas_node.into(); - Ok(( - self.instance_create_surface_from_canvas(&canvas_element)?, - (), - )) + self.instance_create_surface_from_canvas(&canvas_element) } fn instance_request_adapter( @@ -885,8 +910,8 @@ impl crate::context::Context for Context { fn adapter_request_device( &self, - adapter: &Self::AdapterId, - _adapter_data: &Self::AdapterData, + _adapter: &Self::AdapterId, + adapter_data: &Self::AdapterData, desc: &crate::DeviceDescriptor, trace_dir: Option<&std::path::Path>, ) -> Self::RequestDeviceFuture { @@ -914,7 +939,7 @@ impl crate::context::Context for Context { mapped_desc.label(label); } - let device_promise = adapter.0.request_device_with_descriptor(&mapped_desc); + let device_promise = adapter_data.0.request_device_with_descriptor(&mapped_desc); MakeSendFuture::new( wasm_bindgen_futures::JsFuture::from(device_promise), @@ -939,18 +964,18 @@ impl crate::context::Context for Context { fn adapter_features( &self, - adapter: &Self::AdapterId, - _adapter_data: &Self::AdapterData, + _adapter: &Self::AdapterId, + adapter_data: &Self::AdapterData, ) -> wgt::Features { - map_wgt_features(adapter.0.features()) + map_wgt_features(adapter_data.0.features()) } fn adapter_limits( &self, - adapter: &Self::AdapterId, - _adapter_data: &Self::AdapterData, + _adapter: &Self::AdapterId, + adapter_data: &Self::AdapterData, ) -> wgt::Limits { - let limits = adapter.0.limits(); + let limits = adapter_data.0.limits(); wgt::Limits { max_texture_dimension_1d: limits.max_texture_dimension_1d(), max_texture_dimension_2d: limits.max_texture_dimension_2d(), @@ -1022,9 +1047,9 @@ impl crate::context::Context for Context { fn surface_get_capabilities( &self, _surface: &Self::SurfaceId, - _adapter_data: &Self::AdapterData, - _adapter: &Self::AdapterId, _surface_data: &Self::SurfaceData, + _adapter: &Self::AdapterId, + _adapter_data: &Self::AdapterData, ) -> wgt::SurfaceCapabilities { wgt::SurfaceCapabilities { // https://gpuweb.github.io/gpuweb/#supported-context-formats @@ -1041,10 +1066,10 @@ impl crate::context::Context for Context { fn surface_configure( &self, - surface: &Self::SurfaceId, - _surface_data: &Self::SurfaceData, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _surface: &Self::SurfaceId, + surface_data: &Self::SurfaceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, config: &crate::SurfaceConfiguration, ) { if let wgt::PresentMode::Mailbox | wgt::PresentMode::Immediate = config.present_mode { @@ -1060,7 +1085,7 @@ impl crate::context::Context for Context { _ => web_sys::GpuCanvasAlphaMode::Opaque, }; let mut mapped = - web_sys::GpuCanvasConfiguration::new(&device.0, map_texture_format(config.format)); + web_sys::GpuCanvasConfiguration::new(&device_data.0, map_texture_format(config.format)); mapped.usage(config.usage.bits()); mapped.alpha_mode(alpha_mode); let mapped_view_formats = config @@ -1069,22 +1094,23 @@ impl crate::context::Context for Context { .map(|format| JsValue::from(map_texture_format(*format))) .collect::(); mapped.view_formats(&mapped_view_formats); - surface.0.configure(&mapped); + surface_data.0.configure(&mapped); } fn surface_get_current_texture( &self, - surface: &Self::SurfaceId, - _surface_data: &Self::SurfaceData, + _surface: &Self::SurfaceId, + surface_data: &Self::SurfaceData, ) -> ( Option, Option, wgt::SurfaceStatus, Self::SurfaceOutputDetail, ) { + let (surface_id, surface_data) = create_identified(surface_data.0.get_current_texture()); ( - Some(create_identified(surface.0.get_current_texture())), - Some(()), + Some(surface_id), + Some(surface_data), wgt::SurfaceStatus::Good, (), ) @@ -1104,10 +1130,10 @@ impl crate::context::Context for Context { fn device_features( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, ) -> wgt::Features { - map_wgt_features(device.0.features()) + map_wgt_features(device_data.0.features()) } fn device_limits( @@ -1139,8 +1165,8 @@ impl crate::context::Context for Context { )] fn device_create_shader_module( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, desc: crate::ShaderModuleDescriptor, _shader_bound_checks: wgt::ShaderBoundChecks, ) -> (Self::ShaderModuleId, Self::ShaderModuleData) { @@ -1220,10 +1246,7 @@ impl crate::context::Context for Context { if let Some(label) = desc.label { descriptor.label(label); } - ( - create_identified(device.0.create_shader_module(&descriptor)), - (), - ) + create_identified(device_data.0.create_shader_module(&descriptor)) } unsafe fn device_create_shader_module_spirv( @@ -1237,8 +1260,8 @@ impl crate::context::Context for Context { fn device_create_bind_group_layout( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, desc: &crate::BindGroupLayoutDescriptor, ) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) { let mapped_bindings = desc @@ -1331,16 +1354,13 @@ impl crate::context::Context for Context { if let Some(label) = desc.label { mapped_desc.label(label); } - ( - create_identified(device.0.create_bind_group_layout(&mapped_desc)), - (), - ) + create_identified(device_data.0.create_bind_group_layout(&mapped_desc)) } fn device_create_bind_group( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, desc: &crate::BindGroupDescriptor, ) -> (Self::BindGroupId, Self::BindGroupData) { let mapped_entries = desc @@ -1353,8 +1373,9 @@ impl crate::context::Context for Context { offset, size, }) => { - let buffer = &<::BufferId>::from(buffer.id).0; - let mut mapped_buffer_binding = web_sys::GpuBufferBinding::new(buffer); + let buffer: &::BufferData = + downcast_ref(buffer.data.as_ref()); + let mut mapped_buffer_binding = web_sys::GpuBufferBinding::new(&buffer.0); mapped_buffer_binding.offset(offset as f64); if let Some(s) = size { mapped_buffer_binding.size(s.get() as f64); @@ -1365,13 +1386,17 @@ impl crate::context::Context for Context { panic!("Web backend does not support arrays of buffers") } crate::BindingResource::Sampler(sampler) => { - JsValue::from(Self::SamplerId::from(sampler.id).0) + let sampler: &::SamplerData = + downcast_ref(sampler.data.as_ref()); + JsValue::from(&sampler.0) } crate::BindingResource::SamplerArray(..) => { panic!("Web backend does not support arrays of samplers") } crate::BindingResource::TextureView(texture_view) => { - JsValue::from(Self::TextureViewId::from(texture_view.id).0) + let texture_view: &::TextureViewData = + downcast_ref(texture_view.data.as_ref()); + JsValue::from(&texture_view.0) } crate::BindingResource::TextureViewArray(..) => { panic!("Web backend does not support BINDING_INDEXING extension") @@ -1382,46 +1407,47 @@ impl crate::context::Context for Context { }) .collect::(); - let bgl = &<::BindGroupLayoutId>::from(desc.layout.id).0; - let mut mapped_desc = web_sys::GpuBindGroupDescriptor::new(&mapped_entries, bgl); + let bgl: &::BindGroupLayoutData = + downcast_ref(desc.layout.data.as_ref()); + let mut mapped_desc = web_sys::GpuBindGroupDescriptor::new(&mapped_entries, &bgl.0); if let Some(label) = desc.label { mapped_desc.label(label); } - ( - create_identified(device.0.create_bind_group(&mapped_desc)), - (), - ) + create_identified(device_data.0.create_bind_group(&mapped_desc)) } fn device_create_pipeline_layout( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, desc: &crate::PipelineLayoutDescriptor, ) -> (Self::PipelineLayoutId, Self::PipelineLayoutData) { let temp_layouts = desc .bind_group_layouts .iter() - .map(|bgl| Self::BindGroupLayoutId::from(bgl.id).0) + .map(|bgl| { + let bgl: &::BindGroupLayoutData = + downcast_ref(bgl.data.as_ref()); + &bgl.0 + }) .collect::(); let mut mapped_desc = web_sys::GpuPipelineLayoutDescriptor::new(&temp_layouts); if let Some(label) = desc.label { mapped_desc.label(label); } - ( - create_identified(device.0.create_pipeline_layout(&mapped_desc)), - (), - ) + create_identified(device_data.0.create_pipeline_layout(&mapped_desc)) } fn device_create_render_pipeline( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, desc: &crate::RenderPipelineDescriptor, ) -> (Self::RenderPipelineId, Self::RenderPipelineData) { - let module = &<::ShaderModuleId>::from(desc.vertex.module.id).0; - let mut mapped_vertex_state = web_sys::GpuVertexState::new(desc.vertex.entry_point, module); + let module: &::ShaderModuleData = + downcast_ref(desc.vertex.module.data.as_ref()); + let mut mapped_vertex_state = + web_sys::GpuVertexState::new(desc.vertex.entry_point, &module.0); let buffers = desc .vertex @@ -1454,7 +1480,11 @@ impl crate::context::Context for Context { let auto_layout = wasm_bindgen::JsValue::from(web_sys::GpuAutoLayoutMode::Auto); let mut mapped_desc = web_sys::GpuRenderPipelineDescriptor::new( &match desc.layout { - Some(layout) => JsValue::from(Self::PipelineLayoutId::from(layout.id).0), + Some(layout) => { + let layout: &::PipelineLayoutData = + downcast_ref(layout.data.as_ref()); + JsValue::from(&layout.0) + } None => auto_layout, }, &mapped_vertex_state, @@ -1489,9 +1519,10 @@ impl crate::context::Context for Context { None => wasm_bindgen::JsValue::null(), }) .collect::(); - let module = &<::ShaderModuleId>::from(frag.module.id).0; + let module: &::ShaderModuleData = + downcast_ref(frag.module.data.as_ref()); let mapped_fragment_desc = - web_sys::GpuFragmentState::new(frag.entry_point, module, &targets); + web_sys::GpuFragmentState::new(frag.entry_point, &module.0, &targets); mapped_desc.fragment(&mapped_fragment_desc); } @@ -1504,27 +1535,26 @@ impl crate::context::Context for Context { let mapped_primitive = map_primitive_state(&desc.primitive); mapped_desc.primitive(&mapped_primitive); - ( - create_identified(device.0.create_render_pipeline(&mapped_desc)), - (), - ) + create_identified(device_data.0.create_render_pipeline(&mapped_desc)) } fn device_create_compute_pipeline( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, desc: &crate::ComputePipelineDescriptor, ) -> (Self::ComputePipelineId, Self::ComputePipelineData) { - let shader_module = &<::ShaderModuleId>::from(desc.module.id).0; + let shader_module: &::ShaderModuleData = + downcast_ref(desc.module.data.as_ref()); let mapped_compute_stage = - web_sys::GpuProgrammableStage::new(desc.entry_point, shader_module); + web_sys::GpuProgrammableStage::new(desc.entry_point, &shader_module.0); let auto_layout = wasm_bindgen::JsValue::from(web_sys::GpuAutoLayoutMode::Auto); let mut mapped_desc = web_sys::GpuComputePipelineDescriptor::new( &match desc.layout { Some(layout) => { - let layout = Self::PipelineLayoutId::from(layout.id); - JsValue::from(layout.0) + let layout: &::PipelineLayoutData = + downcast_ref(layout.data.as_ref()); + JsValue::from(&layout.0) } None => auto_layout, }, @@ -1533,16 +1563,13 @@ impl crate::context::Context for Context { if let Some(label) = desc.label { mapped_desc.label(label); } - ( - create_identified(device.0.create_compute_pipeline(&mapped_desc)), - (), - ) + create_identified(device_data.0.create_compute_pipeline(&mapped_desc)) } fn device_create_buffer( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, desc: &crate::BufferDescriptor, ) -> (Self::BufferId, Self::BufferData) { let mut mapped_desc = @@ -1551,13 +1578,13 @@ impl crate::context::Context for Context { if let Some(label) = desc.label { mapped_desc.label(label); } - (create_identified(device.0.create_buffer(&mapped_desc)), ()) + create_identified(device_data.0.create_buffer(&mapped_desc)) } fn device_create_texture( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, desc: &crate::TextureDescriptor, ) -> (Self::TextureId, Self::TextureData) { let mut mapped_desc = web_sys::GpuTextureDescriptor::new( @@ -1577,13 +1604,13 @@ impl crate::context::Context for Context { .map(|format| JsValue::from(map_texture_format(*format))) .collect::(); mapped_desc.view_formats(&mapped_view_formats); - (create_identified(device.0.create_texture(&mapped_desc)), ()) + create_identified(device_data.0.create_texture(&mapped_desc)) } fn device_create_sampler( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, desc: &crate::SamplerDescriptor, ) -> (Self::SamplerId, Self::SamplerData) { let mut mapped_desc = web_sys::GpuSamplerDescriptor::new(); @@ -1603,16 +1630,13 @@ impl crate::context::Context for Context { if let Some(label) = desc.label { mapped_desc.label(label); } - ( - create_identified(device.0.create_sampler_with_descriptor(&mapped_desc)), - (), - ) + create_identified(device_data.0.create_sampler_with_descriptor(&mapped_desc)) } fn device_create_query_set( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, desc: &wgt::QuerySetDescriptor, ) -> (Self::QuerySetId, Self::QuerySetData) { let ty = match desc.ty { @@ -1624,36 +1648,30 @@ impl crate::context::Context for Context { if let Some(label) = desc.label { mapped_desc.label(label); } - ( - create_identified(device.0.create_query_set(&mapped_desc)), - (), - ) + create_identified(device_data.0.create_query_set(&mapped_desc)) } fn device_create_command_encoder( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, desc: &crate::CommandEncoderDescriptor, ) -> (Self::CommandEncoderId, Self::CommandEncoderData) { let mut mapped_desc = web_sys::GpuCommandEncoderDescriptor::new(); if let Some(label) = desc.label { mapped_desc.label(label); } - ( - create_identified( - device - .0 - .create_command_encoder_with_descriptor(&mapped_desc), - ), - (), + create_identified( + device_data + .0 + .create_command_encoder_with_descriptor(&mapped_desc), ) } fn device_create_render_bundle_encoder( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, desc: &crate::RenderBundleEncoderDescriptor, ) -> (Self::RenderBundleEncoderId, Self::RenderBundleEncoderData) { let mapped_color_formats = desc @@ -1672,10 +1690,7 @@ impl crate::context::Context for Context { mapped_desc.depth_stencil_format(map_texture_format(ds.format)); } mapped_desc.sample_count(desc.sample_count); - ( - create_identified(device.0.create_render_bundle_encoder(&mapped_desc)), - (), - ) + create_identified(device_data.0.create_render_bundle_encoder(&mapped_desc)) } fn device_drop(&self, _device: &Self::DeviceId, _device_data: &Self::DeviceData) { @@ -1694,15 +1709,15 @@ impl crate::context::Context for Context { fn device_on_uncaptured_error( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, handler: Box, ) { let f = Closure::wrap(Box::new(move |event: web_sys::GpuUncapturedErrorEvent| { let error = crate::Error::from_js(event.error().value_of()); handler(error); }) as Box); - device + device_data .0 .set_onuncapturederror(Some(f.as_ref().unchecked_ref())); // TODO: This will leak the memory associated with the error handler by default. @@ -1711,11 +1726,11 @@ impl crate::context::Context for Context { fn device_push_error_scope( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, filter: crate::ErrorFilter, ) { - device.0.push_error_scope(match filter { + device_data.0.push_error_scope(match filter { crate::ErrorFilter::OutOfMemory => web_sys::GpuErrorFilter::OutOfMemory, crate::ErrorFilter::Validation => web_sys::GpuErrorFilter::Validation, }); @@ -1723,10 +1738,10 @@ impl crate::context::Context for Context { fn device_pop_error_scope( &self, - device: &Self::DeviceId, - _device_data: &Self::DeviceData, + _device: &Self::DeviceId, + device_data: &Self::DeviceData, ) -> Self::PopErrorScopeFuture { - let error_promise = device.0.pop_error_scope(); + let error_promise = device_data.0.pop_error_scope(); MakeSendFuture::new( wasm_bindgen_futures::JsFuture::from(error_promise), future_pop_error_scope, @@ -1735,13 +1750,13 @@ impl crate::context::Context for Context { fn buffer_map_async( &self, - buffer: &Self::BufferId, - _buffer_data: &Self::BufferData, + _buffer: &Self::BufferId, + buffer_data: &Self::BufferData, mode: crate::MapMode, range: Range, callback: Box) + Send + 'static>, ) { - let map_promise = buffer.0.map_async_with_f64_and_f64( + let map_promise = buffer_data.0.map_async_with_f64_and_f64( map_map_mode(mode), range.start as f64, (range.end - range.start) as f64, @@ -1752,11 +1767,11 @@ impl crate::context::Context for Context { fn buffer_get_mapped_range( &self, - buffer: &Self::BufferId, - _buffer_data: &Self::BufferData, + _buffer: &Self::BufferId, + buffer_data: &Self::BufferData, sub_range: Range, ) -> Box { - let array_buffer = buffer.0.get_mapped_range_with_f64_and_f64( + let array_buffer = buffer_data.0.get_mapped_range_with_f64_and_f64( sub_range.start as f64, (sub_range.end - sub_range.start) as f64, ); @@ -1768,14 +1783,14 @@ impl crate::context::Context for Context { }) } - fn buffer_unmap(&self, buffer: &Self::BufferId, _buffer_data: &Self::BufferData) { - buffer.0.unmap(); + fn buffer_unmap(&self, _buffer: &Self::BufferId, buffer_data: &Self::BufferData) { + buffer_data.0.unmap(); } fn texture_create_view( &self, - texture: &Self::TextureId, - _texture_data: &Self::TextureData, + _texture: &Self::TextureId, + texture_data: &Self::TextureData, desc: &crate::TextureViewDescriptor, ) -> (Self::TextureViewId, Self::TextureViewData) { let mut mapped = web_sys::GpuTextureViewDescriptor::new(); @@ -1797,10 +1812,7 @@ impl crate::context::Context for Context { if let Some(label) = desc.label { mapped.label(label); } - ( - create_identified(texture.0.create_view_with_descriptor(&mapped)), - (), - ) + create_identified(texture_data.0.create_view_with_descriptor(&mapped)) } fn surface_drop(&self, _surface: &Self::SurfaceId, _surface_data: &Self::SurfaceData) { @@ -1811,16 +1823,16 @@ impl crate::context::Context for Context { // Dropped automatically } - fn buffer_destroy(&self, buffer: &Self::BufferId, _buffer_data: &Self::BufferData) { - buffer.0.destroy(); + fn buffer_destroy(&self, _buffer: &Self::BufferId, buffer_data: &Self::BufferData) { + buffer_data.0.destroy(); } fn buffer_drop(&self, _buffer: &Self::BufferId, _buffer_data: &Self::BufferData) { // Dropped automatically } - fn texture_destroy(&self, texture: &Self::TextureId, _texture_data: &Self::TextureData) { - texture.0.destroy(); + fn texture_destroy(&self, _texture: &Self::TextureId, texture_data: &Self::TextureData) { + texture_data.0.destroy(); } fn texture_drop(&self, _texture: &Self::TextureId, _texture_data: &Self::TextureData) { @@ -1917,107 +1929,110 @@ impl crate::context::Context for Context { fn compute_pipeline_get_bind_group_layout( &self, - pipeline: &Self::ComputePipelineId, - _pipeline_data: &Self::ComputePipelineData, + _pipeline: &Self::ComputePipelineId, + pipeline_data: &Self::ComputePipelineData, index: u32, ) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) { - ( - create_identified(pipeline.0.get_bind_group_layout(index)), - (), - ) + create_identified(pipeline_data.0.get_bind_group_layout(index)) } fn render_pipeline_get_bind_group_layout( &self, - pipeline: &Self::RenderPipelineId, - _pipeline_data: &Self::ComputePipelineData, + _pipeline: &Self::RenderPipelineId, + pipeline_data: &Self::RenderPipelineData, index: u32, ) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) { - ( - create_identified(pipeline.0.get_bind_group_layout(index)), - (), - ) + create_identified(pipeline_data.0.get_bind_group_layout(index)) } fn command_encoder_copy_buffer_to_buffer( &self, - encoder: &Self::CommandEncoderId, - _encoder_data: &Self::CommandEncoderData, - source: &Self::BufferId, - _source_data: &Self::BufferData, + _encoder: &Self::CommandEncoderId, + encoder_data: &Self::CommandEncoderData, + _source: &Self::BufferId, + source_data: &Self::BufferData, source_offset: wgt::BufferAddress, - destination: &Self::BufferId, - _destination_data: &Self::BufferData, + _destination: &Self::BufferId, + destination_data: &Self::BufferData, destination_offset: wgt::BufferAddress, copy_size: wgt::BufferAddress, ) { - encoder.0.copy_buffer_to_buffer_with_f64_and_f64_and_f64( - &source.0, - source_offset as f64, - &destination.0, - destination_offset as f64, - copy_size as f64, - ) + encoder_data + .0 + .copy_buffer_to_buffer_with_f64_and_f64_and_f64( + &source_data.0, + source_offset as f64, + &destination_data.0, + destination_offset as f64, + copy_size as f64, + ) } fn command_encoder_copy_buffer_to_texture( &self, - encoder: &Self::CommandEncoderId, - _encoder_data: &Self::CommandEncoderData, + _encoder: &Self::CommandEncoderId, + encoder_data: &Self::CommandEncoderData, source: crate::ImageCopyBuffer, destination: crate::ImageCopyTexture, copy_size: wgt::Extent3d, ) { - encoder.0.copy_buffer_to_texture_with_gpu_extent_3d_dict( - &map_buffer_copy_view(source), - &map_texture_copy_view(destination), - &map_extent_3d(copy_size), - ) + encoder_data + .0 + .copy_buffer_to_texture_with_gpu_extent_3d_dict( + &map_buffer_copy_view(source), + &map_texture_copy_view(destination), + &map_extent_3d(copy_size), + ) } fn command_encoder_copy_texture_to_buffer( &self, - encoder: &Self::CommandEncoderId, - _encoder_data: &Self::CommandEncoderData, + _encoder: &Self::CommandEncoderId, + encoder_data: &Self::CommandEncoderData, source: crate::ImageCopyTexture, destination: crate::ImageCopyBuffer, copy_size: wgt::Extent3d, ) { - encoder.0.copy_texture_to_buffer_with_gpu_extent_3d_dict( - &map_texture_copy_view(source), - &map_buffer_copy_view(destination), - &map_extent_3d(copy_size), - ) + encoder_data + .0 + .copy_texture_to_buffer_with_gpu_extent_3d_dict( + &map_texture_copy_view(source), + &map_buffer_copy_view(destination), + &map_extent_3d(copy_size), + ) } fn command_encoder_copy_texture_to_texture( &self, - encoder: &Self::CommandEncoderId, - _encoder_data: &Self::CommandEncoderData, + _encoder: &Self::CommandEncoderId, + encoder_data: &Self::CommandEncoderData, source: crate::ImageCopyTexture, destination: crate::ImageCopyTexture, copy_size: wgt::Extent3d, ) { - encoder.0.copy_texture_to_texture_with_gpu_extent_3d_dict( - &map_texture_copy_view(source), - &map_texture_copy_view(destination), - &map_extent_3d(copy_size), - ) + encoder_data + .0 + .copy_texture_to_texture_with_gpu_extent_3d_dict( + &map_texture_copy_view(source), + &map_texture_copy_view(destination), + &map_extent_3d(copy_size), + ) } fn command_encoder_begin_compute_pass( &self, - encoder: &Self::CommandEncoderId, - _encoder_data: &Self::CommandEncoderData, + _encoder: &Self::CommandEncoderId, + encoder_data: &Self::CommandEncoderData, desc: &crate::ComputePassDescriptor, ) -> (Self::ComputePassId, Self::ComputePassData) { let mut mapped_desc = web_sys::GpuComputePassDescriptor::new(); if let Some(label) = desc.label { mapped_desc.label(label); } - ( - create_identified(encoder.0.begin_compute_pass_with_descriptor(&mapped_desc)), - (), + create_identified( + encoder_data + .0 + .begin_compute_pass_with_descriptor(&mapped_desc), ) } @@ -2025,16 +2040,16 @@ impl crate::context::Context for Context { &self, _encoder: &Self::CommandEncoderId, _encoder_data: &Self::CommandEncoderData, - pass: &mut Self::ComputePassId, - _pass_data: &mut Self::ComputePassData, + _pass: &mut Self::ComputePassId, + pass_data: &mut Self::ComputePassData, ) { - pass.0.end(); + pass_data.0.end(); } fn command_encoder_begin_render_pass( &self, - encoder: &Self::CommandEncoderId, - _encoder_data: &Self::CommandEncoderData, + _encoder: &Self::CommandEncoderId, + encoder_data: &Self::CommandEncoderData, desc: &crate::RenderPassDescriptor<'_, '_>, ) -> (Self::RenderPassId, Self::RenderPassData) { let mapped_color_attachments = desc @@ -2051,18 +2066,21 @@ impl crate::context::Context for Context { crate::LoadOp::Load => web_sys::GpuLoadOp::Load, }; + let view: &::TextureViewData = + downcast_ref(ca.view.data.as_ref()); + let mut mapped_color_attachment = web_sys::GpuRenderPassColorAttachment::new( load_value, map_store_op(ca.ops.store), - &<::TextureViewId>::from(ca.view.id).0, + &view.0, ); if let Some(cv) = clear_value { mapped_color_attachment.clear_value(&cv); } if let Some(rt) = ca.resolve_target { - let texture_view = - &<::TextureViewId>::from(rt.id).0; - mapped_color_attachment.resolve_target(texture_view); + let resolve_target_view: &::TextureViewData = + downcast_ref(rt.data.as_ref()); + mapped_color_attachment.resolve_target(&resolve_target_view.0); } mapped_color_attachment.store_op(map_store_op(ca.ops.store)); @@ -2079,10 +2097,10 @@ impl crate::context::Context for Context { } if let Some(dsa) = &desc.depth_stencil_attachment { + let depth_stencil_attachment: &::TextureViewData = + downcast_ref(&dsa.view.data); let mut mapped_depth_stencil_attachment = - web_sys::GpuRenderPassDepthStencilAttachment::new( - &<::TextureViewId>::from(dsa.view.id).0, - ); + web_sys::GpuRenderPassDepthStencilAttachment::new(&depth_stencil_attachment.0); if let Some(ref ops) = dsa.depth_ops { let load_op = match ops.load { crate::LoadOp::Clear(v) => { @@ -2108,38 +2126,32 @@ impl crate::context::Context for Context { mapped_desc.depth_stencil_attachment(&mapped_depth_stencil_attachment); } - ( - create_identified(encoder.0.begin_render_pass(&mapped_desc)), - (), - ) + create_identified(encoder_data.0.begin_render_pass(&mapped_desc)) } fn command_encoder_end_render_pass( &self, _encoder: &Self::CommandEncoderId, _encoder_data: &Self::CommandEncoderData, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, ) { - pass.0.end(); + pass_data.0.end(); } fn command_encoder_finish( &self, - encoder: Self::CommandEncoderId, - _encoder_data: &mut Self::CommandEncoderData, + _encoder: Self::CommandEncoderId, + encoder_data: &mut Self::CommandEncoderData, ) -> (Self::CommandBufferId, Self::CommandBufferData) { - let label = encoder.0.label(); - ( - create_identified(if label.is_empty() { - encoder.0.finish() - } else { - let mut mapped_desc = web_sys::GpuCommandBufferDescriptor::new(); - mapped_desc.label(&label); - encoder.0.finish_with_descriptor(&mapped_desc) - }), - (), - ) + let label = encoder_data.0.label(); + create_identified(if label.is_empty() { + encoder_data.0.finish() + } else { + let mut mapped_desc = web_sys::GpuCommandBufferDescriptor::new(); + mapped_desc.label(&label); + encoder_data.0.finish_with_descriptor(&mapped_desc) + }) } fn command_encoder_clear_texture( @@ -2154,20 +2166,22 @@ impl crate::context::Context for Context { fn command_encoder_clear_buffer( &self, - encoder: &Self::CommandEncoderId, - _encoder_data: &Self::CommandEncoderData, + _encoder: &Self::CommandEncoderId, + encoder_data: &Self::CommandEncoderData, buffer: &crate::Buffer, offset: wgt::BufferAddress, size: Option, ) { - let buffer_id = &<::BufferId>::from(buffer.id).0; + let buffer: &::BufferData = downcast_ref(buffer.data.as_ref()); match size { - Some(size) => { - encoder - .0 - .clear_buffer_with_f64_and_f64(buffer_id, offset as f64, size.get() as f64) - } - None => encoder.0.clear_buffer_with_f64(buffer_id, offset as f64), + Some(size) => encoder_data.0.clear_buffer_with_f64_and_f64( + &buffer.0, + offset as f64, + size.get() as f64, + ), + None => encoder_data + .0 + .clear_buffer_with_f64(&buffer.0, offset as f64), } } @@ -2202,77 +2216,76 @@ impl crate::context::Context for Context { fn command_encoder_write_timestamp( &self, - encoder: &Self::CommandEncoderId, - _encoder_data: &Self::CommandEncoderData, - query_set: &Self::QuerySetId, - _query_set_data: &Self::QuerySetData, + _encoder: &Self::CommandEncoderId, + encoder_data: &Self::CommandEncoderData, + _query_set: &Self::QuerySetId, + query_set_data: &Self::QuerySetData, query_index: u32, ) { - encoder.0.write_timestamp(&query_set.0, query_index); + encoder_data + .0 + .write_timestamp(&query_set_data.0, query_index); } fn command_encoder_resolve_query_set( &self, - encoder: &Self::CommandEncoderId, - _encoder_data: &Self::CommandEncoderData, - query_set: &Self::QuerySetId, - _query_set_data: &Self::QuerySetData, + _encoder: &Self::CommandEncoderId, + encoder_data: &Self::CommandEncoderData, + _query_set: &Self::QuerySetId, + query_set_data: &Self::QuerySetData, first_query: u32, query_count: u32, - destination: &Self::BufferId, - _destination_data: &Self::BufferData, + _destination: &Self::BufferId, + destination_data: &Self::BufferData, destination_offset: wgt::BufferAddress, ) { - encoder.0.resolve_query_set_with_u32( - &query_set.0, + encoder_data.0.resolve_query_set_with_u32( + &query_set_data.0, first_query, query_count, - &destination.0, + &destination_data.0, destination_offset as u32, ); } fn render_bundle_encoder_finish( &self, - encoder: Self::RenderBundleEncoderId, - _encoder_data: Self::CommandEncoderData, + _encoder: Self::RenderBundleEncoderId, + encoder_data: Self::RenderBundleEncoderData, desc: &crate::RenderBundleDescriptor, ) -> (Self::RenderBundleId, Self::RenderBundleData) { - ( - create_identified(match desc.label { - Some(label) => { - let mut mapped_desc = web_sys::GpuRenderBundleDescriptor::new(); - mapped_desc.label(label); - encoder.0.finish_with_descriptor(&mapped_desc) - } - None => encoder.0.finish(), - }), - (), - ) + create_identified(match desc.label { + Some(label) => { + let mut mapped_desc = web_sys::GpuRenderBundleDescriptor::new(); + mapped_desc.label(label); + encoder_data.0.finish_with_descriptor(&mapped_desc) + } + None => encoder_data.0.finish(), + }) } fn queue_write_buffer( &self, - queue: &Self::QueueId, - _queue_data: &Self::QueueData, - buffer: &Self::BufferId, - _buffer_data: &Self::BufferData, + _queue: &Self::QueueId, + queue_data: &Self::QueueData, + _buffer: &Self::BufferId, + buffer_data: &Self::BufferData, offset: wgt::BufferAddress, data: &[u8], ) { /* Skip the copy once gecko allows BufferSource instead of ArrayBuffer - queue.0.write_buffer_with_f64_and_u8_array_and_f64_and_f64( - &buffer.0, + queue_data.0.write_buffer_with_f64_and_u8_array_and_f64_and_f64( + &buffer_data.0, offset as f64, data, 0f64, data.len() as f64, ); */ - queue + queue_data .0 .write_buffer_with_f64_and_buffer_source_and_f64_and_f64( - &buffer.0, + &buffer_data.0, offset as f64, &js_sys::Uint8Array::from(data).buffer(), 0f64, @@ -2284,12 +2297,12 @@ impl crate::context::Context for Context { &self, _queue: &Self::QueueId, _queue_data: &Self::QueueData, - buffer: &Self::BufferId, - _buffer_data: &Self::BufferData, + _buffer: &Self::BufferId, + buffer_data: &Self::BufferData, offset: wgt::BufferAddress, size: wgt::BufferSize, ) -> Option<()> { - let usage = wgt::BufferUsages::from_bits_truncate(buffer.0.usage()); + let usage = wgt::BufferUsages::from_bits_truncate(buffer_data.0.usage()); // TODO: actually send this down the error scope if !usage.contains(wgt::BufferUsages::COPY_DST) { log::error!("Destination buffer is missing the `COPY_DST` usage flag"); @@ -2310,8 +2323,8 @@ impl crate::context::Context for Context { ); return None; } - if write_size + offset > buffer.0.size() as u64 { - log::error!("copy of {}..{} would end up overrunning the bounds of the destination buffer of size {}", offset, offset + write_size, buffer.0.size()); + if write_size + offset > buffer_data.0.size() as u64 { + log::error!("copy of {}..{} would end up overrunning the bounds of the destination buffer of size {}", offset, offset + write_size, buffer_data.0.size()); return None; } Some(()) @@ -2354,8 +2367,8 @@ impl crate::context::Context for Context { fn queue_write_texture( &self, - queue: &Self::QueueId, - _queue_data: &Self::QueueData, + _queue: &Self::QueueId, + queue_data: &Self::QueueData, texture: crate::ImageCopyTexture, data: &[u8], data_layout: wgt::ImageDataLayout, @@ -2371,14 +2384,14 @@ impl crate::context::Context for Context { mapped_data_layout.offset(data_layout.offset as f64); /* Skip the copy once gecko allows BufferSource instead of ArrayBuffer - queue.0.write_texture_with_u8_array_and_gpu_extent_3d_dict( + queue_data.0.write_texture_with_u8_array_and_gpu_extent_3d_dict( &map_texture_copy_view(texture), data, &mapped_data_layout, &map_extent_3d(size), ); */ - queue + queue_data .0 .write_texture_with_buffer_source_and_gpu_extent_3d_dict( &map_texture_copy_view(texture), @@ -2390,13 +2403,13 @@ impl crate::context::Context for Context { fn queue_copy_external_image_to_texture( &self, - queue: &Self::QueueId, - _queue_data: &Self::QueueData, + _queue: &Self::QueueId, + queue_data: &Self::QueueData, source: &wgt::ImageCopyExternalImage, dest: crate::ImageCopyTextureTagged, size: wgt::Extent3d, ) { - queue + queue_data .0 .copy_external_image_to_texture_with_gpu_extent_3d_dict( &map_external_texture_copy_view(source), @@ -2405,15 +2418,17 @@ impl crate::context::Context for Context { ); } - fn queue_submit>( + fn queue_submit>( &self, - queue: &Self::QueueId, - _queue_data: &Self::QueueData, + _queue: &Self::QueueId, + queue_data: &Self::QueueData, command_buffers: I, ) -> (Self::SubmissionIndex, Self::SubmissionIndexData) { - let temp_command_buffers = command_buffers.map(|i| i.0).collect::(); + let temp_command_buffers = command_buffers + .map(|(_, data)| data.0) + .collect::(); - queue.0.submit(&temp_command_buffers); + queue_data.0.submit(&temp_command_buffers); (Unused, ()) } @@ -2440,27 +2455,28 @@ impl crate::context::Context for Context { fn compute_pass_set_pipeline( &self, - pass: &mut Self::ComputePassId, - _pass_data: &mut Self::ComputePassData, - pipeline: &Self::ComputePipelineId, - _pipeline_data: &Self::ComputePipelineData, + _pass: &mut Self::ComputePassId, + pass_data: &mut Self::ComputePassData, + _pipeline: &Self::ComputePipelineId, + pipeline_data: &Self::ComputePipelineData, ) { - pass.0.set_pipeline(&pipeline.0) + pass_data.0.set_pipeline(&pipeline_data.0) } fn compute_pass_set_bind_group( &self, - pass: &mut Self::ComputePassId, - _pass_data: &mut Self::ComputePassData, + _pass: &mut Self::ComputePassId, + pass_data: &mut Self::ComputePassData, index: u32, - bind_group: &Self::BindGroupId, - _bind_group_data: &Self::BindGroupData, + _bind_group: &Self::BindGroupId, + bind_group_data: &Self::BindGroupData, offsets: &[wgt::DynamicOffset], ) { - pass.0 + pass_data + .0 .set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length( index, - &bind_group.0, + &bind_group_data.0, offsets, 0f64, offsets.len() as u32, @@ -2538,52 +2554,54 @@ impl crate::context::Context for Context { fn compute_pass_dispatch_workgroups( &self, - pass: &mut Self::ComputePassId, - _pass_data: &mut Self::ComputePassData, + _pass: &mut Self::ComputePassId, + pass_data: &mut Self::ComputePassData, x: u32, y: u32, z: u32, ) { - pass.0 + pass_data + .0 .dispatch_workgroups_with_workgroup_count_y_and_workgroup_count_z(x, y, z); } fn compute_pass_dispatch_workgroups_indirect( &self, - pass: &mut Self::ComputePassId, - _pass_data: &mut Self::ComputePassData, - indirect_buffer: &Self::BufferId, - _indirect_buffer_data: &Self::BufferData, + _pass: &mut Self::ComputePassId, + pass_data: &mut Self::ComputePassData, + _indirect_buffer: &Self::BufferId, + indirect_buffer_data: &Self::BufferData, indirect_offset: wgt::BufferAddress, ) { - pass.0 - .dispatch_workgroups_indirect_with_f64(&indirect_buffer.0, indirect_offset as f64); + pass_data + .0 + .dispatch_workgroups_indirect_with_f64(&indirect_buffer_data.0, indirect_offset as f64); } fn render_bundle_encoder_set_pipeline( &self, - encoder: &mut Self::RenderBundleEncoderId, - _encoder_data: &mut Self::RenderBundleEncoderData, - pipeline: &Self::RenderPipelineId, - _pipeline_data: &Self::RenderPipelineData, + _encoder: &mut Self::RenderBundleEncoderId, + encoder_data: &mut Self::RenderBundleEncoderData, + _pipeline: &Self::RenderPipelineId, + pipeline_data: &Self::RenderPipelineData, ) { - encoder.0.set_pipeline(&pipeline.0); + encoder_data.0.set_pipeline(&pipeline_data.0); } fn render_bundle_encoder_set_bind_group( &self, - encoder: &mut Self::RenderBundleEncoderId, - _encoder_data: &mut Self::RenderBundleEncoderData, + _encoder: &mut Self::RenderBundleEncoderId, + encoder_data: &mut Self::RenderBundleEncoderData, index: u32, - bind_group: &Self::BindGroupId, - _bind_group_data: &Self::BindGroupData, + _bind_group: &Self::BindGroupId, + bind_group_data: &Self::BindGroupData, offsets: &[wgt::DynamicOffset], ) { - encoder + encoder_data .0 .set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length( index, - &bind_group.0, + &bind_group_data.0, offsets, 0f64, offsets.len() as u32, @@ -2592,26 +2610,26 @@ impl crate::context::Context for Context { fn render_bundle_encoder_set_index_buffer( &self, - encoder: &mut Self::RenderBundleEncoderId, - _encoder_data: &mut Self::RenderBundleEncoderData, - buffer: &Self::BufferId, - _buffer_data: &Self::BufferData, + _encoder: &mut Self::RenderBundleEncoderId, + encoder_data: &mut Self::RenderBundleEncoderData, + _buffer: &Self::BufferId, + buffer_data: &Self::BufferData, index_format: wgt::IndexFormat, offset: wgt::BufferAddress, size: Option, ) { match size { Some(s) => { - encoder.0.set_index_buffer_with_f64_and_f64( - &buffer.0, + encoder_data.0.set_index_buffer_with_f64_and_f64( + &buffer_data.0, map_index_format(index_format), offset as f64, s.get() as f64, ); } None => { - encoder.0.set_index_buffer_with_f64( - &buffer.0, + encoder_data.0.set_index_buffer_with_f64( + &buffer_data.0, map_index_format(index_format), offset as f64, ); @@ -2621,27 +2639,27 @@ impl crate::context::Context for Context { fn render_bundle_encoder_set_vertex_buffer( &self, - encoder: &mut Self::RenderBundleEncoderId, - _encoder_data: &mut Self::RenderBundleEncoderData, + _encoder: &mut Self::RenderBundleEncoderId, + encoder_data: &mut Self::RenderBundleEncoderData, slot: u32, - buffer: &Self::BufferId, - _buffer_data: &Self::BufferData, + _buffer: &Self::BufferId, + buffer_data: &Self::BufferData, offset: wgt::BufferAddress, size: Option, ) { match size { Some(s) => { - encoder.0.set_vertex_buffer_with_f64_and_f64( + encoder_data.0.set_vertex_buffer_with_f64_and_f64( slot, - &buffer.0, + &buffer_data.0, offset as f64, s.get() as f64, ); } None => { - encoder + encoder_data .0 - .set_vertex_buffer_with_f64(slot, &buffer.0, offset as f64); + .set_vertex_buffer_with_f64(slot, &buffer_data.0, offset as f64); } }; } @@ -2659,12 +2677,12 @@ impl crate::context::Context for Context { fn render_bundle_encoder_draw( &self, - encoder: &mut Self::RenderBundleEncoderId, - _encoder_data: &mut Self::RenderBundleEncoderData, + _encoder: &mut Self::RenderBundleEncoderId, + encoder_data: &mut Self::RenderBundleEncoderData, vertices: Range, instances: Range, ) { - encoder + encoder_data .0 .draw_with_instance_count_and_first_vertex_and_first_instance( vertices.end - vertices.start, @@ -2676,13 +2694,13 @@ impl crate::context::Context for Context { fn render_bundle_encoder_draw_indexed( &self, - encoder: &mut Self::RenderBundleEncoderId, - _encoder_data: &mut Self::RenderBundleEncoderData, + _encoder: &mut Self::RenderBundleEncoderId, + encoder_data: &mut Self::RenderBundleEncoderData, indices: Range, base_vertex: i32, instances: Range, ) { - encoder + encoder_data .0 .draw_indexed_with_instance_count_and_first_index_and_base_vertex_and_first_instance( indices.end - indices.start, @@ -2695,28 +2713,28 @@ impl crate::context::Context for Context { fn render_bundle_encoder_draw_indirect( &self, - encoder: &mut Self::RenderBundleEncoderId, - _encoder_data: &mut Self::RenderBundleEncoderData, - indirect_buffer: &Self::BufferId, - _indirect_buffer_data: &Self::BufferData, + _encoder: &mut Self::RenderBundleEncoderId, + encoder_data: &mut Self::RenderBundleEncoderData, + _indirect_buffer: &Self::BufferId, + indirect_buffer_data: &Self::BufferData, indirect_offset: wgt::BufferAddress, ) { - encoder + encoder_data .0 - .draw_indirect_with_f64(&indirect_buffer.0, indirect_offset as f64); + .draw_indirect_with_f64(&indirect_buffer_data.0, indirect_offset as f64); } fn render_bundle_encoder_draw_indexed_indirect( &self, - encoder: &mut Self::RenderBundleEncoderId, - _encoder_data: &mut Self::RenderBundleEncoderData, - indirect_buffer: &Self::BufferId, - _indirect_buffer_data: &Self::BufferData, + _encoder: &mut Self::RenderBundleEncoderId, + encoder_data: &mut Self::RenderBundleEncoderData, + _indirect_buffer: &Self::BufferId, + indirect_buffer_data: &Self::BufferData, indirect_offset: wgt::BufferAddress, ) { - encoder + encoder_data .0 - .draw_indexed_indirect_with_f64(&indirect_buffer.0, indirect_offset as f64); + .draw_indexed_indirect_with_f64(&indirect_buffer_data.0, indirect_offset as f64); } fn render_bundle_encoder_multi_draw_indirect( @@ -2777,27 +2795,28 @@ impl crate::context::Context for Context { fn render_pass_set_pipeline( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, - pipeline: &Self::RenderPipelineId, - _pipeline_data: &Self::RenderPipelineData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, + _pipeline: &Self::RenderPipelineId, + pipeline_data: &Self::RenderPipelineData, ) { - pass.0.set_pipeline(&pipeline.0); + pass_data.0.set_pipeline(&pipeline_data.0); } fn render_pass_set_bind_group( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, index: u32, - bind_group: &Self::BindGroupId, - _bind_group_data: &Self::BindGroupData, + _bind_group: &Self::BindGroupId, + bind_group_data: &Self::BindGroupData, offsets: &[wgt::DynamicOffset], ) { - pass.0 + pass_data + .0 .set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length( index, - &bind_group.0, + &bind_group_data.0, offsets, 0f64, offsets.len() as u32, @@ -2806,26 +2825,26 @@ impl crate::context::Context for Context { fn render_pass_set_index_buffer( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, - buffer: &Self::BufferId, - _buffer_data: &Self::BufferData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, + _buffer: &Self::BufferId, + buffer_data: &Self::BufferData, index_format: wgt::IndexFormat, offset: wgt::BufferAddress, size: Option, ) { match size { Some(s) => { - pass.0.set_index_buffer_with_f64_and_f64( - &buffer.0, + pass_data.0.set_index_buffer_with_f64_and_f64( + &buffer_data.0, map_index_format(index_format), offset as f64, s.get() as f64, ); } None => { - pass.0.set_index_buffer_with_f64( - &buffer.0, + pass_data.0.set_index_buffer_with_f64( + &buffer_data.0, map_index_format(index_format), offset as f64, ); @@ -2835,26 +2854,27 @@ impl crate::context::Context for Context { fn render_pass_set_vertex_buffer( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, slot: u32, - buffer: &Self::BufferId, - _buffer_data: &Self::BufferData, + _buffer: &Self::BufferId, + buffer_data: &Self::BufferData, offset: wgt::BufferAddress, size: Option, ) { match size { Some(s) => { - pass.0.set_vertex_buffer_with_f64_and_f64( + pass_data.0.set_vertex_buffer_with_f64_and_f64( slot, - &buffer.0, + &buffer_data.0, offset as f64, s.get() as f64, ); } None => { - pass.0 - .set_vertex_buffer_with_f64(slot, &buffer.0, offset as f64); + pass_data + .0 + .set_vertex_buffer_with_f64(slot, &buffer_data.0, offset as f64); } }; } @@ -2872,12 +2892,13 @@ impl crate::context::Context for Context { fn render_pass_draw( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, vertices: Range, instances: Range, ) { - pass.0 + pass_data + .0 .draw_with_instance_count_and_first_vertex_and_first_instance( vertices.end - vertices.start, instances.end - instances.start, @@ -2888,13 +2909,14 @@ impl crate::context::Context for Context { fn render_pass_draw_indexed( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, indices: Range, base_vertex: i32, instances: Range, ) { - pass.0 + pass_data + .0 .draw_indexed_with_instance_count_and_first_index_and_base_vertex_and_first_instance( indices.end - indices.start, instances.end - instances.start, @@ -2906,26 +2928,28 @@ impl crate::context::Context for Context { fn render_pass_draw_indirect( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, - indirect_buffer: &Self::BufferId, - _indirect_buffer_data: &Self::BufferData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, + _indirect_buffer: &Self::BufferId, + indirect_buffer_data: &Self::BufferData, indirect_offset: wgt::BufferAddress, ) { - pass.0 - .draw_indirect_with_f64(&indirect_buffer.0, indirect_offset as f64); + pass_data + .0 + .draw_indirect_with_f64(&indirect_buffer_data.0, indirect_offset as f64); } fn render_pass_draw_indexed_indirect( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, - indirect_buffer: &Self::BufferId, - _indirect_buffer_data: &Self::BufferData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, + _indirect_buffer: &Self::BufferId, + indirect_buffer_data: &Self::BufferData, indirect_offset: wgt::BufferAddress, ) { - pass.0 - .draw_indexed_indirect_with_f64(&indirect_buffer.0, indirect_offset as f64); + pass_data + .0 + .draw_indexed_indirect_with_f64(&indirect_buffer_data.0, indirect_offset as f64); } fn render_pass_multi_draw_indirect( @@ -2986,30 +3010,31 @@ impl crate::context::Context for Context { fn render_pass_set_blend_constant( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, color: wgt::Color, ) { - pass.0 + pass_data + .0 .set_blend_constant_with_gpu_color_dict(&map_color(color)); } fn render_pass_set_scissor_rect( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, x: u32, y: u32, width: u32, height: u32, ) { - pass.0.set_scissor_rect(x, y, width, height); + pass_data.0.set_scissor_rect(x, y, width, height); } fn render_pass_set_viewport( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, x: f32, y: f32, width: f32, @@ -3017,17 +3042,18 @@ impl crate::context::Context for Context { min_depth: f32, max_depth: f32, ) { - pass.0 + pass_data + .0 .set_viewport(x, y, width, height, min_depth, max_depth); } fn render_pass_set_stencil_reference( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, reference: u32, ) { - pass.0.set_stencil_reference(reference); + pass_data.0.set_stencil_reference(reference); } fn render_pass_insert_debug_marker( @@ -3091,14 +3117,16 @@ impl crate::context::Context for Context { fn render_pass_execute_bundles<'a>( &self, - pass: &mut Self::RenderPassId, - _pass_data: &mut Self::RenderPassData, - render_bundles: Box + 'a>, + _pass: &mut Self::RenderPassId, + pass_data: &mut Self::RenderPassData, + render_bundles: Box< + dyn Iterator + 'a, + >, ) { let mapped = render_bundles - .map(|bundle| bundle.0) + .map(|(_, bundle_data)| &bundle_data.0) .collect::(); - pass.0.execute_bundles(&mapped); + pass_data.0.execute_bundles(&mapped); } } diff --git a/wgpu/src/context.rs b/wgpu/src/context.rs index d45f2a6321..11a495aa7c 100644 --- a/wgpu/src/context.rs +++ b/wgpu/src/context.rs @@ -570,7 +570,7 @@ pub trait Context: Debug + Send + Sized + Sync { dest: crate::ImageCopyTextureTagged, size: wgt::Extent3d, ); - fn queue_submit>( + fn queue_submit>( &self, queue: &Self::QueueId, queue_data: &Self::QueueData, @@ -987,7 +987,9 @@ pub trait Context: Debug + Send + Sized + Sync { &self, pass: &mut Self::RenderPassId, pass_data: &mut Self::RenderPassData, - render_bundles: Box + 'a>, + render_bundles: Box< + dyn Iterator + 'a, + >, ); } @@ -1025,6 +1027,7 @@ impl ObjectId { } } + #[allow(dead_code)] pub fn id(&self) -> NonZeroU64 { self.id.unwrap() } @@ -1038,7 +1041,7 @@ impl ObjectId { static_assertions::assert_impl_all!(ObjectId: Send, Sync); -fn downcast_ref(data: &crate::Data) -> &T { +pub(crate) fn downcast_ref(data: &crate::Data) -> &T { strict_assert!(data.is::()); // Copied from std. unsafe { &*(data as *const dyn Any as *const T) } @@ -1501,7 +1504,7 @@ pub(crate) trait DynContext: Debug + Send + Sync { &self, queue: &ObjectId, queue_data: &crate::Data, - command_buffers: Box + 'a>, + command_buffers: Box)> + 'a>, ) -> (ObjectId, Arc); fn queue_get_timestamp_period(&self, queue: &ObjectId, queue_data: &crate::Data) -> f32; fn queue_on_submitted_work_done( @@ -1902,7 +1905,7 @@ pub(crate) trait DynContext: Debug + Send + Sync { &self, pass: &mut ObjectId, pass_data: &mut crate::Data, - render_bundles: Box + 'a>, + render_bundles: Box + 'a>, ); } @@ -2902,11 +2905,14 @@ where &self, queue: &ObjectId, queue_data: &crate::Data, - command_buffers: Box + 'a>, + command_buffers: Box)> + 'a>, ) -> (ObjectId, Arc) { let queue = ::from(*queue); let queue_data = downcast_ref(queue_data); - let command_buffers = command_buffers.into_iter().map(::from); + let command_buffers = command_buffers.into_iter().map(|(id, data)| { + let command_buffer_data: ::CommandBufferData = *data.downcast().unwrap(); + (::from(id), command_buffer_data) + }); let (submission_index, data) = Context::queue_submit(self, &queue, queue_data, command_buffers); (submission_index.into(), Arc::new(data) as _) @@ -3843,15 +3849,14 @@ where &self, pass: &mut ObjectId, pass_data: &mut crate::Data, - render_bundles: Box + 'a>, + render_bundles: Box + 'a>, ) { let mut pass = ::from(*pass); let pass_data = downcast_mut::(pass_data); - let render_bundles = Box::new( - render_bundles - .into_iter() - .map(|id| ::from(*id)), - ); + let render_bundles = Box::new(render_bundles.into_iter().map(|(id, data)| { + let render_bundle_data: &::RenderBundleData = downcast_ref(data); + (::from(*id), render_bundle_data) + })); Context::render_pass_execute_bundles(self, &mut pass, pass_data, render_bundles) } } diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 253262dc7e..8e77391d84 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -567,7 +567,7 @@ impl ComputePipeline { pub struct CommandBuffer { context: Arc, id: Option, - data: Box, + data: Option>, } static_assertions::assert_impl_all!(CommandBuffer: Send, Sync); @@ -575,7 +575,7 @@ impl Drop for CommandBuffer { fn drop(&mut self) { if !thread::panicking() { if let Some(ref id) = self.id { - self.context.command_buffer_drop(id, self.data.as_ref()); + self.context.command_buffer_drop(id, &self.data.take()); } } } @@ -2740,7 +2740,7 @@ impl CommandEncoder { CommandBuffer { context: Arc::clone(&self.context), id: Some(id), - data, + data: Some(data), } } @@ -3224,7 +3224,11 @@ impl<'a> RenderPass<'a> { &*self.parent.context, &mut self.id, self.data.as_mut(), - Box::new(render_bundles.into_iter().map(|rb| &rb.id)), + Box::new( + render_bundles + .into_iter() + .map(|rb| (&rb.id, rb.data.as_ref())), + ), ) } } @@ -4034,7 +4038,7 @@ impl Queue { Box::new( command_buffers .into_iter() - .map(|mut comb| comb.id.take().unwrap()), + .map(|mut comb| (comb.id.take().unwrap(), comb.data.take().unwrap())), ), );