Auto merge of #26564 - kunalmohan:gpu-id-rotation, r=jdm

Upgrade wgpu version to "0.5.0" and add server-side code for id recycling for WebGPU

<!-- Please describe your changes on the following line: -->
I have updated the cargo.lock to use a wgpu-core at a more recent commit where IdentityHandlerFactory was introduced.
r?@kvark

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-05-21 13:24:55 -04:00 committed by GitHub
commit 94063d67a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 509 additions and 344 deletions

388
Cargo.lock generated
View file

@ -161,11 +161,11 @@ checksum = "3ae7d751998c189c1d4468cf0a39bb2eae052a9c58d50ebb3b9591ee3813ad50"
[[package]]
name = "ash"
version = "0.29.0"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "003d1fb2eb12eb06d4a03dbe02eea67a9fac910fa97932ab9e3a75b96a1ea5e5"
checksum = "69daec0742947f33a85931fa3cb0ce5f07929159dcbd1f0cbb5b2912e2978509"
dependencies = [
"shared_library",
"libloading 0.5.2",
]
[[package]]
@ -429,6 +429,12 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "bumpalo"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5356f1d23ee24a1f785a56d1d1a5f0fd5b0f6a0c0fb2412ce11da71649ab78f6"
[[package]]
name = "byte-slice-cast"
version = "0.2.0"
@ -728,18 +734,27 @@ dependencies = [
"objc",
]
[[package]]
name = "cocoa"
version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f7b6f3f7f4f0b3ec5c5039aaa9e8c3cef97a7a480a400fd62944841314f293d"
dependencies = [
"bitflags",
"block",
"core-foundation 0.7.0",
"core-graphics 0.19.0",
"foreign-types",
"libc",
"objc",
]
[[package]]
name = "color_quant"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a475fc4af42d83d28adf72968d9bcfaf035a1a9381642d8e85d8a04957767b0d"
[[package]]
name = "colorful"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bca1619ff57dd7a56b58a8e25ef4199f123e78e503fe1653410350a1b98ae65"
[[package]]
name = "combine"
version = "3.5.2"
@ -1796,9 +1811,9 @@ dependencies = [
[[package]]
name = "gfx-auxil"
version = "0.1.0"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "572eee952a9a23c99cfe3e4fd95d277784058a89ac3c77ff6fa3d80a4e321919"
checksum = "67bdbf8e8d6883c70e5a0d7379ad8ab3ac95127a3761306b36122d8f1c177a8e"
dependencies = [
"fxhash",
"gfx-hal",
@ -1807,19 +1822,19 @@ dependencies = [
[[package]]
name = "gfx-backend-dx11"
version = "0.4.2"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c66c77836ff26cf9916e5c8745715a22eae1fc61d994ffa0bea8a7dbd708ece2"
checksum = "92de0ddc0fde1a89b2a0e92dcc6bbb554bd34af0135e53a28d5ef064611094a4"
dependencies = [
"bitflags",
"gfx-auxil",
"gfx-hal",
"libloading 0.5.2",
"log",
"parking_lot",
"parking_lot 0.10.2",
"range-alloc",
"raw-window-handle",
"smallvec 0.6.13",
"smallvec 1.3.0",
"spirv_cross",
"winapi",
"wio",
@ -1827,9 +1842,9 @@ dependencies = [
[[package]]
name = "gfx-backend-dx12"
version = "0.4.1"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6e913cc800fb12eaba2c420091a02aca9aafbefd672600dfc5b52654343d341"
checksum = "37365e2927d55cefac0d3f78dfd1d3119fbb13a8bd7afe2409d729961fee22fc"
dependencies = [
"bitflags",
"d3d12",
@ -1838,16 +1853,16 @@ dependencies = [
"log",
"range-alloc",
"raw-window-handle",
"smallvec 0.6.13",
"smallvec 1.3.0",
"spirv_cross",
"winapi",
]
[[package]]
name = "gfx-backend-empty"
version = "0.4.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d383e6bc48867cb37d298a20139fd1eec298f8f6d594690cd1c50ef25470cc7"
checksum = "b67bd2d7bc022b257ddbdabc5fa3b10c29c292372c3409f2b6a6e3f4e11cdb85"
dependencies = [
"gfx-hal",
"raw-window-handle",
@ -1855,60 +1870,83 @@ dependencies = [
[[package]]
name = "gfx-backend-metal"
version = "0.4.0"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8de5c71f18ba805c95b84d6c78c472ef44485a6fc46e3b49fe1e6739c8d7b0c0"
checksum = "205f3ca8e74ed814ea2c0206d47d8925077673cab2e21f9b12d48ff781cf87ee"
dependencies = [
"arrayvec 0.5.1",
"bitflags",
"block",
"cocoa 0.19.1",
"cocoa 0.20.1",
"copyless",
"core-graphics 0.17.3",
"core-graphics 0.19.0",
"foreign-types",
"gfx-auxil",
"gfx-hal",
"lazy_static",
"log",
"metal",
"metal 0.18.0",
"objc",
"parking_lot",
"parking_lot 0.10.2",
"range-alloc",
"raw-window-handle",
"smallvec 0.6.13",
"smallvec 1.3.0",
"spirv_cross",
"storage-map",
]
[[package]]
name = "gfx-backend-vulkan"
version = "0.4.0"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62538fedd66a78968a162e8e1a29d085ffbc97f8782634684b2f7da7aea59207"
checksum = "45ff36feae801fa23d29acd74082603a0145a697a23595757dd4e78828ab33da"
dependencies = [
"arrayvec 0.5.1",
"ash",
"byteorder",
"core-graphics 0.17.3",
"core-graphics 0.19.0",
"gfx-hal",
"lazy_static",
"log",
"objc",
"raw-window-handle",
"smallvec 0.6.13",
"smallvec 1.3.0",
"winapi",
"x11",
]
[[package]]
name = "gfx-hal"
version = "0.4.1"
name = "gfx-descriptor"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c88981665c780447bb08eb099e1ded330754a7246719bab927ee4a949c0ba7f"
checksum = "1bf35f5d66d1bc56e63e68d7528441453f25992bd954b84309d23c659df2c5da"
dependencies = [
"fxhash",
"gfx-hal",
"log",
]
[[package]]
name = "gfx-hal"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc96180204064c9493e0fe4a9efeb721e0ac59fe8e1906d0c659142a93114fb1"
dependencies = [
"bitflags",
"raw-window-handle",
"smallvec 0.6.13",
]
[[package]]
name = "gfx-memory"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2eed6cda674d9cd4d92229102dbd544292124533d236904f987e9afab456137"
dependencies = [
"fxhash",
"gfx-hal",
"hibitset",
"log",
"slab",
]
[[package]]
@ -2767,6 +2805,15 @@ dependencies = [
"rayon",
]
[[package]]
name = "js-sys"
version = "0.3.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa5a448de267e7358beaf4a5d849518fe9a0c13fce7afd44b06e68550e5562a7"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "jstraceable_derive"
version = "0.0.1"
@ -2817,7 +2864,7 @@ dependencies = [
"msg",
"net_traits",
"num-traits",
"parking_lot",
"parking_lot 0.9.0",
"profile_traits",
"range",
"rayon",
@ -2861,7 +2908,7 @@ dependencies = [
"mitochondria",
"msg",
"net_traits",
"parking_lot",
"parking_lot 0.9.0",
"range",
"rayon",
"rayon_croissant",
@ -2903,7 +2950,7 @@ dependencies = [
"metrics",
"msg",
"net_traits",
"parking_lot",
"parking_lot 0.9.0",
"profile_traits",
"range",
"rayon",
@ -2948,7 +2995,7 @@ dependencies = [
"metrics",
"msg",
"net_traits",
"parking_lot",
"parking_lot 0.9.0",
"profile_traits",
"range",
"script",
@ -3167,9 +3214,9 @@ dependencies = [
[[package]]
name = "lock_api"
version = "0.3.1"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8912e782533a93a167888781b836336a6ca5da6175c05944c86cf28c31104dc"
checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75"
dependencies = [
"scopeguard",
]
@ -3369,6 +3416,21 @@ dependencies = [
"objc",
]
[[package]]
name = "metal"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e198a0ee42bdbe9ef2c09d0b9426f3b2b47d90d93a4a9b0395c4cea605e92dc0"
dependencies = [
"bitflags",
"block",
"cocoa 0.20.1",
"core-graphics 0.19.0",
"foreign-types",
"log",
"objc",
]
[[package]]
name = "metrics"
version = "0.0.1"
@ -3552,7 +3614,7 @@ dependencies = [
"lazy_static",
"malloc_size_of",
"malloc_size_of_derive",
"parking_lot",
"parking_lot 0.9.0",
"serde",
"servo_url",
"size_of_test",
@ -3565,6 +3627,18 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "451a9a05d2a32c566c897835e0ea95cf79ed2fdfe957924045a1721a36c9980f"
[[package]]
name = "naga"
version = "0.1.0"
source = "git+https://github.com/gfx-rs/naga?rev=bce6358eb1026c13d2f1c6d365af37afe8869a86#bce6358eb1026c13d2f1c6d365af37afe8869a86"
dependencies = [
"bitflags",
"fxhash",
"log",
"num-traits",
"spirv_headers",
]
[[package]]
name = "net"
version = "0.0.1"
@ -3886,10 +3960,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252"
dependencies = [
"lock_api",
"parking_lot_core",
"parking_lot_core 0.6.2",
"rustc_version",
]
[[package]]
name = "parking_lot"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e"
dependencies = [
"lock_api",
"parking_lot_core 0.7.2",
]
[[package]]
name = "parking_lot_core"
version = "0.6.2"
@ -3905,6 +3989,20 @@ dependencies = [
"winapi",
]
[[package]]
name = "parking_lot_core"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3"
dependencies = [
"cfg-if",
"cloudabi",
"libc",
"redox_syscall",
"smallvec 1.3.0",
"winapi",
]
[[package]]
name = "paste"
version = "0.1.6"
@ -3952,25 +4050,16 @@ version = "0.2.0"
source = "git+https://github.com/servo/webrender#01082a9091ab98c392af8934d04271eb1dd546df"
dependencies = [
"euclid",
"peek-poke-derive 0.2.1",
"peek-poke-derive 0.2.1 (git+https://github.com/servo/webrender)",
]
[[package]]
name = "peek-poke"
version = "0.2.0"
source = "git+https://github.com/kvark/peek-poke?rev=969bd7fe2be1a83f87916dc8b388c63cfd457075#969bd7fe2be1a83f87916dc8b388c63cfd457075"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d93fd6a575ebf1ac2668d08443c97a22872cfb463fd8b7ddd141e9f6be59af2f"
dependencies = [
"peek-poke-derive 0.2.0",
]
[[package]]
name = "peek-poke-derive"
version = "0.2.0"
source = "git+https://github.com/kvark/peek-poke?rev=969bd7fe2be1a83f87916dc8b388c63cfd457075#969bd7fe2be1a83f87916dc8b388c63cfd457075"
dependencies = [
"proc-macro2 1.0.1",
"quote 1.0.2",
"syn",
"peek-poke-derive 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -3985,6 +4074,19 @@ dependencies = [
"unicode-xid 0.2.0",
]
[[package]]
name = "peek-poke-derive"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fb44a25c5bba983be0fc8592dfaf3e6d0935ce8be0c6b15b2a39507af34a926"
dependencies = [
"proc-macro2 1.0.1",
"quote 1.0.2",
"syn",
"synstructure",
"unicode-xid 0.2.0",
]
[[package]]
name = "peeking_take_while"
version = "0.1.2"
@ -4425,16 +4527,6 @@ version = "0.6.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1132f845907680735a84409c3bebc64d1364a5683ffbce899550cd09d5eaefc1"
[[package]]
name = "relevant"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbc232e13d37f4547f5b9b42a5efc380cabe5dbc1807f8b893580640b2ab0308"
dependencies = [
"cfg-if",
"log",
]
[[package]]
name = "remove_dir_all"
version = "0.5.2"
@ -4444,33 +4536,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "rendy-descriptor"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f475bcc0505946e998590f1f0545c52ef4b559174a1b353a7ce6638def8b621e"
dependencies = [
"gfx-hal",
"log",
"relevant",
"smallvec 0.6.13",
]
[[package]]
name = "rendy-memory"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed492161a819feae7f27f418bb16035276ac20649c60d756699152cb5c1960ec"
dependencies = [
"colorful",
"gfx-hal",
"hibitset",
"log",
"relevant",
"slab",
"smallvec 0.6.13",
]
[[package]]
name = "rle-decode-fast"
version = "1.0.1"
@ -4486,6 +4551,17 @@ dependencies = [
"serde",
]
[[package]]
name = "ron"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ece421e0c4129b90e4a35b6f625e472e96c552136f5093a2f4fa2bbb75a62d5"
dependencies = [
"base64 0.10.1",
"bitflags",
"serde",
]
[[package]]
name = "rust-argon2"
version = "0.7.0"
@ -4618,7 +4694,7 @@ dependencies = [
"msg",
"net_traits",
"num-traits",
"parking_lot",
"parking_lot 0.9.0",
"percent-encoding",
"phf",
"phf_codegen",
@ -4681,7 +4757,7 @@ dependencies = [
"metrics",
"msg",
"net_traits",
"parking_lot",
"parking_lot 0.9.0",
"profile_traits",
"range",
"script_traits",
@ -5222,16 +5298,6 @@ dependencies = [
"opaque-debug",
]
[[package]]
name = "shared_library"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11"
dependencies = [
"lazy_static",
"libc",
]
[[package]]
name = "shellwords"
version = "1.0.0"
@ -5397,10 +5463,23 @@ checksum = "b72d540d5c565dbe1f891d7e21ceb21d2649508306782f1066989fccb0b363d3"
[[package]]
name = "spirv_cross"
version = "0.16.0"
source = "git+https://github.com/servo/spirv_cross?branch=wgpu-servo#636677bad724797789239c16e6d332e9b4d97b86"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a33a9478e9c78782dd694d05dee074703a9c4c74b511de742b88a7e8149f1b37"
dependencies = [
"cc",
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "spirv_headers"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f1418983d16481227ffa3ab3cf44ef92eebc9a76c092fbcd4c51a64ff032622"
dependencies = [
"bitflags",
"num-traits",
]
[[package]]
@ -5505,7 +5584,7 @@ dependencies = [
"num-traits",
"num_cpus",
"owning_ref",
"parking_lot",
"parking_lot 0.9.0",
"precomputed-hash",
"rayon",
"regex",
@ -5605,9 +5684,9 @@ dependencies = [
"libc",
"log",
"mach",
"metal",
"metal 0.17.0",
"objc",
"parking_lot",
"parking_lot 0.9.0",
"wayland-sys 0.24.0",
"winapi",
"winit",
@ -6192,9 +6271,9 @@ checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168"
[[package]]
name = "vec_map"
version = "0.8.0"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version_check"
@ -6260,6 +6339,60 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d"
[[package]]
name = "wasm-bindgen"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3c7d40d09cdbf0f4895ae58cf57d92e1e57a9dd8ed2e8390514b54a47cc5551"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3972e137ebf830900db522d6c8fd74d1900dcfc733462e9a12e942b00b4ac94"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"proc-macro2 1.0.1",
"quote 1.0.2",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cd85aa2c579e8892442954685f0d801f9129de24fa2136b2c6a539c76b65776"
dependencies = [
"quote 1.0.2",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eb197bd3a47553334907ffd2f16507b4f4f01bbec3ac921a7719e0decdfe72a"
dependencies = [
"proc-macro2 1.0.1",
"quote 1.0.2",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a91c2916119c17a8e316507afaaa2dd94b47646048014bbdf6bef098c1bb58ad"
[[package]]
name = "wayland-client"
version = "0.21.13"
@ -6389,6 +6522,7 @@ dependencies = [
"servo_config",
"smallvec 0.6.13",
"wgpu-core",
"wgpu-types",
]
[[package]]
@ -6420,7 +6554,7 @@ dependencies = [
"num-traits",
"plane-split",
"rayon",
"ron",
"ron 0.1.7",
"serde",
"serde_json",
"smallvec 1.3.0",
@ -6519,8 +6653,8 @@ dependencies = [
[[package]]
name = "wgpu-core"
version = "0.1.0"
source = "git+https://github.com/gfx-rs/wgpu#4f937c04e12572a56d96a160c30888ceecc930a9"
version = "0.5.0"
source = "git+https://github.com/gfx-rs/wgpu#a203333c3e144cfd431c812213966ee32ae59d98"
dependencies = [
"arrayvec 0.5.1",
"bitflags",
@ -6531,15 +6665,29 @@ dependencies = [
"gfx-backend-empty",
"gfx-backend-metal",
"gfx-backend-vulkan",
"gfx-descriptor",
"gfx-hal",
"gfx-memory",
"log",
"parking_lot",
"peek-poke 0.2.0 (git+https://github.com/kvark/peek-poke?rev=969bd7fe2be1a83f87916dc8b388c63cfd457075)",
"rendy-descriptor",
"rendy-memory",
"naga",
"parking_lot 0.10.2",
"peek-poke 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ron 0.5.1",
"serde",
"smallvec 1.3.0",
"spirv_headers",
"vec_map",
"wgpu-types",
]
[[package]]
name = "wgpu-types"
version = "0.5.0"
source = "git+https://github.com/gfx-rs/wgpu#a203333c3e144cfd431c812213966ee32ae59d98"
dependencies = [
"bitflags",
"peek-poke 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde",
]
[[package]]
@ -6595,7 +6743,7 @@ dependencies = [
"libc",
"log",
"objc",
"parking_lot",
"parking_lot 0.9.0",
"percent-encoding",
"smithay-client-toolkit",
"wayland-client",

View file

@ -30,6 +30,5 @@ opt-level = 3
mio = { git = "https://github.com/servo/mio.git", branch = "servo" }
# https://github.com/retep998/winapi-rs/pull/816
winapi = { git = "https://github.com/servo/winapi-rs", branch = "patch-1" }
spirv_cross = { git = "https://github.com/servo/spirv_cross", branch = "wgpu-servo" }
surfman-chains = { git = "https://github.com/asajeffrey/surfman-chains" }
surfman = { git = "https://github.com/servo/surfman" }

View file

@ -455,7 +455,7 @@ impl<'a> CanvasData<'a> {
pub fn restore_context_state(&mut self) {
if let Some(state) = self.saved_states.pop() {
mem::replace(&mut self.state, state);
let _ = mem::replace(&mut self.state, state);
self.drawtarget.set_transform(&self.state.transform);
self.drawtarget.pop_clip();
}

View file

@ -20,8 +20,8 @@ use ipc_channel::router::ROUTER;
use js::jsapi::Heap;
use script_traits::ScriptMsg;
use std::rc::Rc;
use webgpu::wgpu;
use webgpu::{WebGPUResponse, WebGPUResponseResult};
use webgpu::wgt::PowerPreference;
use webgpu::{wgpu, WebGPUResponse, WebGPUResponseResult};
#[dom_struct]
pub struct GPU {
@ -109,11 +109,9 @@ impl GPUMethods for GPU {
let promise = Promise::new_in_current_realm(global, comp);
let sender = response_async(&promise, self);
let power_preference = match options.powerPreference {
Some(GPUPowerPreference::Low_power) => wgpu::instance::PowerPreference::LowPower,
Some(GPUPowerPreference::High_performance) => {
wgpu::instance::PowerPreference::HighPerformance
},
None => wgpu::instance::PowerPreference::Default,
Some(GPUPowerPreference::Low_power) => PowerPreference::LowPower,
Some(GPUPowerPreference::High_performance) => PowerPreference::HighPerformance,
None => PowerPreference::Default,
};
let ids = global.wgpu_id_hub().lock().create_adapter_ids();
@ -121,7 +119,10 @@ impl GPUMethods for GPU {
if script_to_constellation_chan
.send(ScriptMsg::RequestAdapter(
sender,
wgpu::instance::RequestAdapterOptions { power_preference },
wgpu::instance::RequestAdapterOptions {
power_preference,
compatible_surface: None,
},
ids,
))
.is_err()

View file

@ -20,7 +20,7 @@ use dom_struct::dom_struct;
use js::jsapi::{Heap, JSObject};
use std::ptr::NonNull;
use std::rc::Rc;
use webgpu::{wgpu, WebGPU, WebGPUAdapter, WebGPURequest, WebGPUResponse};
use webgpu::{wgt, WebGPU, WebGPUAdapter, WebGPURequest, WebGPUResponse};
#[dom_struct]
pub struct GPUAdapter {
@ -80,11 +80,11 @@ impl GPUAdapterMethods for GPUAdapter {
fn RequestDevice(&self, descriptor: &GPUDeviceDescriptor, comp: InRealm) -> Rc<Promise> {
let promise = Promise::new_in_current_realm(&self.global(), comp);
let sender = response_async(&promise, self);
let desc = wgpu::instance::DeviceDescriptor {
extensions: wgpu::instance::Extensions {
let desc = wgt::DeviceDescriptor {
extensions: wgt::Extensions {
anisotropic_filtering: descriptor.extensions.anisotropicFiltering,
},
limits: wgpu::instance::Limits {
limits: wgt::Limits {
max_bind_groups: descriptor.limits.maxBindGroups,
},
};

View file

@ -11,21 +11,14 @@ use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::trace::RootedTraceableBox;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpu::{response_async, AsyncWGPUListener};
use crate::dom::promise::Promise;
use crate::realms::InRealm;
use dom_struct::dom_struct;
use js::jsapi::{Heap, JSObject};
use js::jsval::UndefinedValue;
use js::rust::jsapi_wrapped::{DetachArrayBuffer, IsPromiseObject, RejectPromise};
use js::rust::MutableHandle;
use js::typedarray::{ArrayBuffer, CreateWith};
use js::typedarray::ArrayBuffer;
use std::cell::Cell;
use std::ptr;
use std::rc::Rc;
use webgpu::{
wgpu::resource::BufferUsage, WebGPU, WebGPUBuffer, WebGPUDevice, WebGPURequest, WebGPUResponse,
};
use webgpu::{WebGPU, WebGPUBuffer, WebGPUDevice, WebGPURequest};
// https://gpuweb.github.io/gpuweb/#buffer-state
#[derive(Clone, MallocSizeOf)]
@ -193,72 +186,6 @@ impl GPUBufferMethods for GPUBuffer {
*self.state.borrow_mut() = GPUBufferState::Destroyed;
}
#[allow(unsafe_code)]
/// https://gpuweb.github.io/gpuweb/#dom-gpubuffer-mapreadasync
fn MapReadAsync(&self, comp: InRealm) -> Rc<Promise> {
// Step 1 & 2
let promise = Promise::new_in_current_realm(&self.global(), comp);
match *self.state.borrow() {
GPUBufferState::Unmapped => {
match BufferUsage::from_bits(self.usage) {
Some(usage) => {
if !usage.contains(BufferUsage::MAP_READ) {
// TODO: Record validation error on the current scope
promise.reject_error(Error::Abort);
return promise;
};
},
None => {
promise.reject_error(Error::Abort);
return promise;
},
}
},
_ => {
promise.reject_error(Error::Abort);
return promise;
},
}
// Step 3
self.mapping.set(*promise.promise_obj());
// Step 4
*self.state.borrow_mut() = GPUBufferState::MappedPendingForReading;
// Step 5.1
if unsafe {
ArrayBuffer::create(
*self.global().get_cx(),
CreateWith::Length(self.size as u32),
MutableHandle::from_raw(self.mapping.handle_mut()),
)
}
.is_err()
{
promise.reject_error(Error::Operation);
return promise;
}
let sender = response_async(&promise, self);
if self
.channel
.0
.send(WebGPURequest::MapReadAsync {
sender,
buffer_id: self.buffer.0,
device_id: self.device.0,
usage: self.usage,
size: self.size,
})
.is_err()
{
promise.reject_error(Error::Operation);
return promise;
}
// Step 6
promise
}
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
self.label.borrow().clone()
@ -269,25 +196,3 @@ impl GPUBufferMethods for GPUBuffer {
*self.label.borrow_mut() = value;
}
}
impl AsyncWGPUListener for GPUBuffer {
#[allow(unsafe_code)]
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>) {
match response {
WebGPUResponse::MapReadAsync(bytes) => unsafe {
match ArrayBuffer::from(self.mapping.get()) {
Ok(mut array_buffer) => {
// Step 5.2
array_buffer.update(&bytes);
// Step 5.3
*self.state.borrow_mut() = GPUBufferState::MappedForReading;
// Step 5.4
promise.resolve_native(&array_buffer);
},
_ => promise.reject_error(Error::Operation),
};
},
_ => promise.reject_error(Error::Operation),
}
}
}

View file

@ -19,7 +19,7 @@ use dom_struct::dom_struct;
use ipc_channel::ipc;
use std::cell::Cell;
use std::collections::HashSet;
use webgpu::wgpu::resource::BufferUsage;
use webgpu::wgt::BufferUsage;
use webgpu::{WebGPU, WebGPUCommandEncoder, WebGPURequest};
const BUFFER_COPY_ALIGN_MASK: u64 = 3;

View file

@ -36,12 +36,13 @@ pub struct GPUComputePassEncoder {
}
impl GPUComputePassEncoder {
#[allow(unsafe_code)]
fn new_inherited(channel: WebGPU, parent: &GPUCommandEncoder) -> GPUComputePassEncoder {
GPUComputePassEncoder {
channel,
reflector_: Reflector::new(),
label: DomRefCell::new(None),
raw_pass: RefCell::new(Some(RawPass::new_compute(parent.id().0))),
raw_pass: RefCell::new(Some(unsafe { RawPass::new_compute(parent.id().0) })),
command_encoder: Dom::from_ref(parent),
}
}

View file

@ -42,10 +42,12 @@ use js::typedarray::{ArrayBuffer, CreateWith};
use std::collections::{HashMap, HashSet};
use std::ptr::{self, NonNull};
use webgpu::wgpu::binding_model::{
BindGroupBinding, BindGroupLayoutBinding, BindingResource, BindingType, BufferBinding,
ShaderStage,
BindGroupEntry, BindGroupLayoutEntry, BindingResource, BindingType, BufferBinding,
};
use webgpu::wgt::{
BufferDescriptor, BufferUsage, ShaderStage, TextureComponentType, TextureFormat,
TextureViewDimension,
};
use webgpu::wgpu::resource::{BufferDescriptor, BufferUsage};
use webgpu::{WebGPU, WebGPUDevice, WebGPUQueue, WebGPURequest};
#[dom_struct]
@ -108,7 +110,7 @@ impl GPUDevice {
fn validate_buffer_descriptor(
&self,
descriptor: &GPUBufferDescriptor,
) -> (bool, BufferDescriptor) {
) -> (bool, BufferDescriptor<std::string::String>) {
// TODO: Record a validation error in the current scope if the descriptor is invalid.
let wgpu_usage = BufferUsage::from_bits(descriptor.usage);
let valid = wgpu_usage.is_some() && descriptor.size > 0;
@ -119,6 +121,7 @@ impl GPUDevice {
BufferDescriptor {
size: descriptor.size,
usage: wgpu_usage.unwrap(),
label: Default::default(),
},
)
} else {
@ -127,6 +130,7 @@ impl GPUDevice {
BufferDescriptor {
size: 0,
usage: BufferUsage::STORAGE,
label: Default::default(),
},
)
}
@ -276,18 +280,9 @@ impl GPUDeviceMethods for GPUDevice {
max_storage_textures_per_shader_stage: limits.maxStorageTexturesPerShaderStage as i32,
max_samplers_per_shader_stage: limits.maxSamplersPerShaderStage as i32,
};
validation_map.insert(
webgpu::wgpu::binding_model::ShaderStage::VERTEX,
maxLimits.clone(),
);
validation_map.insert(
webgpu::wgpu::binding_model::ShaderStage::FRAGMENT,
maxLimits.clone(),
);
validation_map.insert(
webgpu::wgpu::binding_model::ShaderStage::COMPUTE,
maxLimits.clone(),
);
validation_map.insert(ShaderStage::VERTEX, maxLimits.clone());
validation_map.insert(ShaderStage::FRAGMENT, maxLimits.clone());
validation_map.insert(ShaderStage::COMPUTE, maxLimits.clone());
let mut max_dynamic_uniform_buffers_per_pipeline_layout =
limits.maxDynamicUniformBuffersPerPipelineLayout as i32;
let mut max_dynamic_storage_buffers_per_pipeline_layout =
@ -344,14 +339,23 @@ impl GPUDeviceMethods for GPUDevice {
};
BindingType::SampledTexture
},
GPUBindingType::Storage_texture => {
GPUBindingType::Readonly_storage_texture => {
if let Some(limit) = validation_map.get_mut(&visibility) {
limit.max_storage_textures_per_shader_stage -= 1;
}
if bind.hasDynamicOffset {
valid = false
};
BindingType::StorageTexture
BindingType::ReadonlyStorageTexture
},
GPUBindingType::Writeonly_storage_texture => {
if let Some(limit) = validation_map.get_mut(&visibility) {
limit.max_storage_textures_per_shader_stage -= 1;
}
if bind.hasDynamicOffset {
valid = false
};
BindingType::WriteonlyStorageTexture
},
GPUBindingType::Sampler => {
if let Some(limit) = validation_map.get_mut(&visibility) {
@ -364,16 +368,19 @@ impl GPUDeviceMethods for GPUDevice {
},
};
BindGroupLayoutBinding {
BindGroupLayoutEntry {
binding: bind.binding,
visibility,
ty,
dynamic: bind.hasDynamicOffset,
has_dynamic_offset: bind.hasDynamicOffset,
multisampled: bind.multisampled,
texture_dimension: webgpu::wgpu::resource::TextureViewDimension::D2, // Use as default for now
// Use as default for now
texture_component_type: TextureComponentType::Float,
storage_texture_format: TextureFormat::Rgba8UnormSrgb,
view_dimension: TextureViewDimension::D2,
}
})
.collect::<Vec<BindGroupLayoutBinding>>();
.collect::<Vec<BindGroupLayoutEntry>>();
// bindings are unique
valid &= storeBindings.len() == bindings.len();
@ -523,7 +530,7 @@ impl GPUDeviceMethods for GPUDevice {
let bindings = descriptor
.entries
.iter()
.map(|bind| BindGroupBinding {
.map(|bind| BindGroupEntry {
binding: bind.binding,
resource: BindingResource::Buffer(BufferBinding {
buffer: bind.resource.buffer.id().0,

View file

@ -9,8 +9,8 @@ use webgpu::wgpu::{
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandEncoderId, ComputePipelineId,
DeviceId, PipelineLayoutId, ShaderModuleId,
},
Backend,
};
use webgpu::wgt::Backend;
#[derive(Debug)]
pub struct IdentityHub {

View file

@ -239,7 +239,7 @@ impl BodyOperations for Response {
match body {
NetTraitsResponseBody::Done(bytes) => Some(bytes),
body => {
mem::replace(&mut *self.body.borrow_mut(), body);
let _ = mem::replace(&mut *self.body.borrow_mut(), body);
None
},
}

View file

@ -28,5 +28,7 @@ enum GPUBindingType {
"readonly-storage-buffer",
"sampler",
"sampled-texture",
"storage-texture"
"readonly-storage-texture",
"writeonly-storage-texture",
//"comparison-sampler",
};

View file

@ -5,7 +5,7 @@
// https://gpuweb.github.io/gpuweb/#gpubuffer
[Exposed=(Window, DedicatedWorker), Serializable, Pref="dom.webgpu.enabled"]
interface GPUBuffer {
Promise<ArrayBuffer> mapReadAsync();
//Promise<ArrayBuffer> mapReadAsync();
// Promise<ArrayBuffer> mapWriteAsync();
void unmap();

View file

@ -337,7 +337,7 @@ impl<L: CalcNodeLeaf> CalcNode<L> {
($slot:expr) => {{
let dummy = Self::MinMax(Default::default(), MinMaxOp::Max);
let result = mem::replace($slot, dummy);
mem::replace(self, result);
let _ = mem::replace(self, result);
}};
}
match *self {
@ -464,7 +464,7 @@ impl<L: CalcNodeLeaf> CalcNode<L> {
replace_self_with!(&mut children[0]);
} else {
// Else put our simplified children back.
mem::replace(children_slot, children.into_boxed_slice().into());
let _ = mem::replace(children_slot, children.into_boxed_slice().into());
}
},
Self::Leaf(ref mut l) => {

View file

@ -15,7 +15,8 @@ embedder_traits = {path = "../embedder_traits"}
ipc-channel = "0.14"
log = "0.4"
malloc_size_of = { path = "../malloc_size_of" }
serde = "1.0"
serde = { version = "1.0", features = ["serde_derive"] }
servo_config = {path = "../config"}
smallvec = { version = "0.6", features = ["serde"] }
wgpu-core = { version = "0.1.0", git = "https://github.com/gfx-rs/wgpu", features = ["serde"] }
wgpu-core = { version = "0.5.0", git = "https://github.com/gfx-rs/wgpu", features = ["trace", "replay"] }
wgpu-types = { version = "0.5.0", git = "https://github.com/gfx-rs/wgpu", features = ["trace", "replay"] }

View file

@ -0,0 +1,114 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use ipc_channel::ipc::IpcSender;
use serde::{Deserialize, Serialize};
use wgpu::{
hub::{GlobalIdentityHandlerFactory, IdentityHandler, IdentityHandlerFactory},
id::{
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandBufferId, ComputePipelineId,
DeviceId, PipelineLayoutId, RenderPipelineId, SamplerId, ShaderModuleId, SurfaceId,
SwapChainId, TextureId, TextureViewId, TypedId,
},
};
use wgt::Backend;
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum WebGPUMsg {
FreeAdapter(AdapterId),
FreeDevice(DeviceId),
FreeBuffer(BufferId),
FreeSwapChain(SwapChainId),
FreePipelineLayout(PipelineLayoutId),
FreeComputePipeline(ComputePipelineId),
FreeRenderPipeline(RenderPipelineId),
FreeBindGroup(BindGroupId),
FreeBindGroupLayout(BindGroupLayoutId),
FreeCommandBuffer(CommandBufferId),
FreeTexture(TextureId),
FreeTextureView(TextureViewId),
FreeSampler(SamplerId),
FreeSurface(SurfaceId),
FreeShaderModule(ShaderModuleId),
}
#[derive(Debug)]
pub struct IdentityRecycler {
sender: IpcSender<WebGPUMsg>,
}
pub struct IdentityRecyclerFactory {
pub sender: IpcSender<WebGPUMsg>,
}
macro_rules! impl_identity_handler {
($id:ty, $st:tt, $($var:tt)*) => {
impl IdentityHandler<$id> for IdentityRecycler {
type Input = $id;
fn process(&self, id: $id, _backend: Backend) -> $id {
log::debug!("process {} {:?}", $st, id);
//debug_assert_eq!(id.unzip().2, backend);
id
}
fn free(&self, id: $id) {
log::debug!("free {} {:?}", $st, id);
let msg = $($var)*(id);
if self.sender.send(msg).is_err() {
log::error!("Failed to send {:?}", msg);
}
}
}
};
}
impl_identity_handler!(AdapterId, "adapter", WebGPUMsg::FreeAdapter);
impl_identity_handler!(DeviceId, "device", WebGPUMsg::FreeDevice);
impl_identity_handler!(SurfaceId, "surface", WebGPUMsg::FreeSurface);
impl_identity_handler!(SamplerId, "sampler", WebGPUMsg::FreeSampler);
impl_identity_handler!(TextureId, "texture", WebGPUMsg::FreeTexture);
impl_identity_handler!(TextureViewId, "texture_view", WebGPUMsg::FreeTextureView);
impl_identity_handler!(BufferId, "buffer", WebGPUMsg::FreeBuffer);
impl_identity_handler!(BindGroupId, "bind_group", WebGPUMsg::FreeBindGroup);
impl_identity_handler!(SwapChainId, "swap_chain", WebGPUMsg::FreeSwapChain);
impl_identity_handler!(ShaderModuleId, "shader_module", WebGPUMsg::FreeShaderModule);
impl_identity_handler!(
RenderPipelineId,
"render_pipeline",
WebGPUMsg::FreeRenderPipeline
);
impl_identity_handler!(
ComputePipelineId,
"compute_pipeline",
WebGPUMsg::FreeComputePipeline
);
impl_identity_handler!(
CommandBufferId,
"command_buffer",
WebGPUMsg::FreeCommandBuffer
);
impl_identity_handler!(
BindGroupLayoutId,
"bind_group_layout",
WebGPUMsg::FreeBindGroupLayout
);
impl_identity_handler!(
PipelineLayoutId,
"pipeline_layout",
WebGPUMsg::FreePipelineLayout
);
impl<I: TypedId + Clone + std::fmt::Debug> IdentityHandlerFactory<I> for IdentityRecyclerFactory
where
I: TypedId + Clone + std::fmt::Debug,
IdentityRecycler: IdentityHandler<I>,
{
type Filter = IdentityRecycler;
fn spawn(&self, _min_index: u32) -> Self::Filter {
IdentityRecycler {
sender: self.sender.clone(),
}
}
}
impl GlobalIdentityHandlerFactory for IdentityRecyclerFactory {}

View file

@ -6,21 +6,28 @@
extern crate log;
#[macro_use]
pub extern crate wgpu_core as wgpu;
pub extern crate wgpu_types as wgt;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender, IpcSharedMemory};
mod identity;
use identity::{IdentityRecyclerFactory, WebGPUMsg};
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use serde::{Deserialize, Serialize};
use servo_config::pref;
use smallvec::SmallVec;
use std::ptr;
use wgpu::{
binding_model::{BindGroupBinding, BindGroupLayoutBinding},
binding_model::{
BindGroupDescriptor, BindGroupEntry, BindGroupLayoutDescriptor, BindGroupLayoutEntry,
},
id::{
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandBufferId, CommandEncoderId,
ComputePipelineId, DeviceId, PipelineLayoutId, QueueId, ShaderModuleId,
},
instance::{DeviceDescriptor, RequestAdapterOptions},
resource::BufferDescriptor,
BufferAddress,
instance::RequestAdapterOptions,
};
use wgt::{BufferAddress, BufferDescriptor, CommandBufferDescriptor, DeviceDescriptor};
#[derive(Debug, Deserialize, Serialize)]
pub enum WebGPUResponse {
@ -34,7 +41,6 @@ pub enum WebGPUResponse {
queue_id: WebGPUQueue,
_descriptor: DeviceDescriptor,
},
MapReadAsync(IpcSharedMemory),
}
pub type WebGPUResponseResult = Result<WebGPUResponse, String>;
@ -60,25 +66,25 @@ pub enum WebGPURequest {
device_id: DeviceId,
bind_group_id: BindGroupId,
bind_group_layout_id: BindGroupLayoutId,
bindings: Vec<BindGroupBinding>,
bindings: Vec<BindGroupEntry>,
},
CreateBindGroupLayout {
sender: IpcSender<WebGPUBindGroupLayout>,
device_id: DeviceId,
bind_group_layout_id: BindGroupLayoutId,
bindings: Vec<BindGroupLayoutBinding>,
bindings: Vec<BindGroupLayoutEntry>,
},
CreateBuffer {
sender: IpcSender<WebGPUBuffer>,
device_id: DeviceId,
buffer_id: BufferId,
descriptor: BufferDescriptor,
descriptor: BufferDescriptor<String>,
},
CreateBufferMapped {
sender: IpcSender<WebGPUBuffer>,
device_id: DeviceId,
buffer_id: BufferId,
descriptor: BufferDescriptor,
descriptor: BufferDescriptor<String>,
},
CreateCommandEncoder {
sender: IpcSender<WebGPUCommandEncoder>,
@ -109,13 +115,6 @@ pub enum WebGPURequest {
},
DestroyBuffer(BufferId),
Exit(IpcSender<()>),
MapReadAsync {
sender: IpcSender<WebGPUResponseResult>,
buffer_id: BufferId,
device_id: DeviceId,
usage: u32,
size: u64,
},
RequestAdapter {
sender: IpcSender<WebGPUResponseResult>,
options: RequestAdapterOptions,
@ -154,7 +153,7 @@ impl WebGPU {
Ok(sender_and_receiver) => sender_and_receiver,
Err(e) => {
warn!(
"Failed to create sender and receiciver for WGPU thread ({})",
"Failed to create sender and receiver for WGPU thread ({})",
e
);
return None;
@ -162,10 +161,21 @@ impl WebGPU {
};
let sender_clone = sender.clone();
let (script_sender, _script_recv) = match ipc::channel() {
Ok(sender_and_receiver) => sender_and_receiver,
Err(e) => {
warn!(
"Failed to create receiver and sender for WGPU thread ({})",
e
);
return None;
},
};
if let Err(e) = std::thread::Builder::new()
.name("WGPU".to_owned())
.spawn(move || {
WGPU::new(receiver, sender_clone).run();
WGPU::new(receiver, sender_clone, script_sender).run();
})
{
warn!("Failed to spwan WGPU thread ({})", e);
@ -184,7 +194,7 @@ impl WebGPU {
struct WGPU {
receiver: IpcReceiver<WebGPURequest>,
sender: IpcSender<WebGPURequest>,
global: wgpu::hub::Global<()>,
global: wgpu::hub::Global<IdentityRecyclerFactory>,
adapters: Vec<WebGPUAdapter>,
devices: Vec<WebGPUDevice>,
// Track invalid adapters https://gpuweb.github.io/gpuweb/#invalid
@ -192,21 +202,24 @@ struct WGPU {
}
impl WGPU {
fn new(receiver: IpcReceiver<WebGPURequest>, sender: IpcSender<WebGPURequest>) -> Self {
fn new(
receiver: IpcReceiver<WebGPURequest>,
sender: IpcSender<WebGPURequest>,
script_sender: IpcSender<WebGPUMsg>,
) -> Self {
let factory = IdentityRecyclerFactory {
sender: script_sender,
};
WGPU {
receiver,
sender,
global: wgpu::hub::Global::new("wgpu-core"),
global: wgpu::hub::Global::new("wgpu-core", factory),
adapters: Vec::new(),
devices: Vec::new(),
_invalid_adapters: Vec::new(),
}
}
fn deinit(self) {
self.global.delete()
}
fn run(mut self) {
while let Ok(msg) = self.receiver.recv() {
match msg {
@ -217,7 +230,7 @@ impl WGPU {
let global = &self.global;
let command_buffer_id = gfx_select!(command_encoder_id => global.command_encoder_finish(
command_encoder_id,
&wgpu::command::CommandBufferDescriptor::default()
&CommandBufferDescriptor::default()
));
if let Err(e) = sender.send(WebGPUCommandBuffer(command_buffer_id)) {
warn!(
@ -252,10 +265,11 @@ impl WGPU {
bindings,
} => {
let global = &self.global;
let descriptor = wgpu_core::binding_model::BindGroupDescriptor {
let descriptor = BindGroupDescriptor {
layout: bind_group_layout_id,
bindings: bindings.as_ptr(),
bindings_length: bindings.len(),
entries: bindings.as_ptr(),
entries_length: bindings.len(),
label: ptr::null(),
};
let bg_id = gfx_select!(bind_group_id =>
global.device_create_bind_group(device_id, &descriptor, bind_group_id));
@ -275,9 +289,10 @@ impl WGPU {
bindings,
} => {
let global = &self.global;
let descriptor = wgpu_core::binding_model::BindGroupLayoutDescriptor {
bindings: bindings.as_ptr(),
bindings_length: bindings.len(),
let descriptor = BindGroupLayoutDescriptor {
entries: bindings.as_ptr(),
entries_length: bindings.len(),
label: ptr::null(),
};
let bgl_id = gfx_select!(bind_group_layout_id =>
global.device_create_bind_group_layout(device_id, &descriptor, bind_group_layout_id));
@ -297,7 +312,12 @@ impl WGPU {
descriptor,
} => {
let global = &self.global;
let id = gfx_select!(buffer_id => global.device_create_buffer(device_id, &descriptor, buffer_id));
let desc = BufferDescriptor {
size: descriptor.size,
usage: descriptor.usage,
label: ptr::null(),
};
let id = gfx_select!(buffer_id => global.device_create_buffer(device_id, &desc, buffer_id));
let buffer = WebGPUBuffer(id);
if let Err(e) = sender.send(buffer) {
warn!(
@ -313,8 +333,13 @@ impl WGPU {
descriptor,
} => {
let global = &self.global;
let desc = BufferDescriptor {
size: descriptor.size,
usage: descriptor.usage,
label: ptr::null(),
};
let (buffer_id, _arr_buff_ptr) = gfx_select!(buffer_id =>
global.device_create_buffer_mapped(device_id, &descriptor, buffer_id));
global.device_create_buffer_mapped(device_id, &desc, buffer_id));
let buffer = WebGPUBuffer(buffer_id);
if let Err(e) = sender.send(buffer) {
@ -418,55 +443,12 @@ impl WGPU {
gfx_select!(buffer => global.buffer_destroy(buffer));
},
WebGPURequest::Exit(sender) => {
self.deinit();
drop(self.global);
if let Err(e) = sender.send(()) {
warn!("Failed to send response to WebGPURequest::Exit ({})", e)
}
return;
},
WebGPURequest::MapReadAsync {
sender,
buffer_id,
device_id,
usage,
size,
} => {
let global = &self.global;
let on_read = move |status: wgpu::resource::BufferMapAsyncStatus,
ptr: *const u8| {
match status {
wgpu::resource::BufferMapAsyncStatus::Success => {
let array_buffer =
unsafe { std::slice::from_raw_parts(ptr, size as usize) };
if let Err(e) = sender.send(Ok(WebGPUResponse::MapReadAsync(
IpcSharedMemory::from_bytes(array_buffer),
))) {
warn!(
"Failed to send response to WebGPURequest::MapReadAsync ({})",
e
)
}
},
_ => {
if let Err(e) = sender
.send(Err("MapReadAsync: Failed to map buffer".to_owned()))
{
warn!(
"Failed to send response to WebGPURequest::MapReadAsync ({})",
e
)
}
},
}
};
gfx_select!(buffer_id => global.buffer_map_async(
buffer_id,
wgpu::resource::BufferUsage::from_bits(usage).unwrap(),
0..size,
wgpu::resource::BufferMapOperation::Read(Box::new(on_read))
));
gfx_select!(device_id => global.device_poll(device_id, true));
},
WebGPURequest::RequestAdapter {
sender,
options,
@ -523,6 +505,7 @@ impl WGPU {
let id = gfx_select!(device_id => global.adapter_request_device(
adapter_id.0,
&descriptor,
None,
device_id
));

View file

@ -1 +1 @@
nightly-2020-04-08
nightly-2020-05-15

View file

@ -35,6 +35,10 @@ packages = [
"peek-poke",
"peek-poke-derive",
"wayland-sys",
"metal",
"parking_lot",
"parking_lot_core",
"ron",
# https://github.com/servo/servo/pull/23288#issuecomment-494687746
"gl_generator",