aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-11-28 11:05:19 -0500
committerGitHub <noreply@github.com>2019-11-28 11:05:19 -0500
commitb0012a62b2ac97bad2a12c048de830362e0ea4bc (patch)
tree0961191ed62b3bd819a58ef5f74e9173a0c9d550
parent5f1681ad25921e7bb779a9223445167124e44e14 (diff)
parentb26598d47094a24db3f8041c8e070229106e419d (diff)
downloadservo-b0012a62b2ac97bad2a12c048de830362e0ea4bc.tar.gz
servo-b0012a62b2ac97bad2a12c048de830362e0ea4bc.zip
Auto merge of #24883 - szeged:id_management, r=jdm
Add WebGPU identity management <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes addresses a part of #24706 <!-- 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.--> cc @jdm, @kvark, @zakorgy <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
-rw-r--r--components/script/dom/bindings/trace.rs2
-rw-r--r--components/script/dom/gpu.rs3
-rw-r--r--components/script/dom/identityhub.rs47
-rw-r--r--components/script/dom/mod.rs1
-rw-r--r--components/script/dom/navigator.rs12
-rw-r--r--components/webgpu/lib.rs20
6 files changed, 72 insertions, 13 deletions
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs
index 5f10ad44446..65717bb81bf 100644
--- a/components/script/dom/bindings/trace.rs
+++ b/components/script/dom/bindings/trace.rs
@@ -39,6 +39,7 @@ use crate::dom::bindings::utils::WindowProxyHandler;
use crate::dom::document::PendingRestyle;
use crate::dom::htmlimageelement::SourceSet;
use crate::dom::htmlmediaelement::{HTMLMediaElementFetchContext, MediaFrameRenderer};
+use crate::dom::identityhub::Identities;
use crate::task::TaskBox;
use app_units::Au;
use canvas_traits::canvas::{
@@ -504,6 +505,7 @@ unsafe_no_jsmanaged_fields!(WebGLVertexArrayId);
unsafe_no_jsmanaged_fields!(WebGLVersion);
unsafe_no_jsmanaged_fields!(WebGLSLVersion);
unsafe_no_jsmanaged_fields!(WebGPU);
+unsafe_no_jsmanaged_fields!(RefCell<Identities>);
unsafe_no_jsmanaged_fields!(WebGPUAdapter);
unsafe_no_jsmanaged_fields!(WebXRSwapChainId);
unsafe_no_jsmanaged_fields!(MediaList);
diff --git a/components/script/dom/gpu.rs b/components/script/dom/gpu.rs
index cbde108bc01..4e47620052e 100644
--- a/components/script/dom/gpu.rs
+++ b/components/script/dom/gpu.rs
@@ -5,6 +5,7 @@
use crate::compartments::InCompartment;
use crate::dom::bindings::codegen::Bindings::GPUBinding::GPURequestAdapterOptions;
use crate::dom::bindings::codegen::Bindings::GPUBinding::{self, GPUMethods, GPUPowerPreference};
+use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
use crate::dom::bindings::error::Error;
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
@@ -120,6 +121,7 @@ impl GPUMethods for GPU {
Some(GPUPowerPreference::High_performance) => wgpu::PowerPreference::HighPerformance,
None => wgpu::PowerPreference::Default,
};
+ let id = self.global().as_window().Navigator().create_adapter_id();
match self.wgpu_channel() {
Some(channel) => {
@@ -128,6 +130,7 @@ impl GPUMethods for GPU {
.send(WebGPURequest::RequestAdapter(
sender,
wgpu::RequestAdapterOptions { power_preference },
+ id,
))
.unwrap();
},
diff --git a/components/script/dom/identityhub.rs b/components/script/dom/identityhub.rs
new file mode 100644
index 00000000000..489eaacc78d
--- /dev/null
+++ b/components/script/dom/identityhub.rs
@@ -0,0 +1,47 @@
+/* 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 webgpu::wgpu::{AdapterId, Backend, DeviceId, IdentityManager, SurfaceId};
+
+#[derive(Debug)]
+pub struct IdentityHub {
+ adapters: IdentityManager<AdapterId>,
+ devices: IdentityManager<DeviceId>,
+}
+
+impl IdentityHub {
+ fn new(backend: Backend) -> Self {
+ IdentityHub {
+ adapters: IdentityManager::new(backend),
+ devices: IdentityManager::new(backend),
+ }
+ }
+}
+
+#[derive(Debug)]
+pub struct Identities {
+ surface: IdentityManager<SurfaceId>,
+ hub: IdentityHub,
+}
+
+impl Identities {
+ pub fn new() -> Self {
+ let hub = if cfg!(any(target_os = "linux", target_os = "windows")) {
+ IdentityHub::new(Backend::Vulkan)
+ } else if cfg!(any(target_os = "ios", target_os = "macos")) {
+ IdentityHub::new(Backend::Metal)
+ } else {
+ IdentityHub::new(Backend::Empty)
+ };
+
+ Identities {
+ surface: IdentityManager::new(Backend::Empty),
+ hub,
+ }
+ }
+
+ pub fn create_adapter_id(&mut self) -> AdapterId {
+ self.hub.adapters.alloc()
+ }
+}
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
index 9fbf2e0cc6e..d348633df88 100644
--- a/components/script/dom/mod.rs
+++ b/components/script/dom/mod.rs
@@ -391,6 +391,7 @@ pub mod htmltrackelement;
pub mod htmlulistelement;
pub mod htmlunknownelement;
pub mod htmlvideoelement;
+pub mod identityhub;
pub mod imagedata;
pub mod inputevent;
pub mod keyboardevent;
diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs
index cb8fb2365cd..9121f7ef54d 100644
--- a/components/script/dom/navigator.rs
+++ b/components/script/dom/navigator.rs
@@ -12,6 +12,7 @@ use crate::dom::bindings::str::DOMString;
use crate::dom::bluetooth::Bluetooth;
use crate::dom::gamepadlist::GamepadList;
use crate::dom::gpu::GPU;
+use crate::dom::identityhub::Identities;
use crate::dom::mediadevices::MediaDevices;
use crate::dom::mediasession::MediaSession;
use crate::dom::mimetypearray::MimeTypeArray;
@@ -23,7 +24,9 @@ use crate::dom::serviceworkercontainer::ServiceWorkerContainer;
use crate::dom::window::Window;
use crate::dom::xr::XR;
use dom_struct::dom_struct;
+use std::cell::RefCell;
use std::rc::Rc;
+use webgpu::wgpu::AdapterId;
#[dom_struct]
pub struct Navigator {
@@ -38,6 +41,8 @@ pub struct Navigator {
permissions: MutNullableDom<Permissions>,
mediasession: MutNullableDom<MediaSession>,
gpu: MutNullableDom<GPU>,
+ #[ignore_malloc_size_of = "Defined in wgpu"]
+ gpu_id_hub: RefCell<Identities>,
}
impl Navigator {
@@ -54,6 +59,7 @@ impl Navigator {
permissions: Default::default(),
mediasession: Default::default(),
gpu: Default::default(),
+ gpu_id_hub: RefCell::new(Identities::new()),
}
}
@@ -66,6 +72,12 @@ impl Navigator {
}
}
+impl Navigator {
+ pub fn create_adapter_id(&self) -> AdapterId {
+ self.gpu_id_hub.borrow_mut().create_adapter_id()
+ }
+}
+
impl NavigatorMethods for Navigator {
// https://html.spec.whatwg.org/multipage/#dom-navigator-product
fn Product(&self) -> DOMString {
diff --git a/components/webgpu/lib.rs b/components/webgpu/lib.rs
index 5cb449c6c3c..6439fc9f5e9 100644
--- a/components/webgpu/lib.rs
+++ b/components/webgpu/lib.rs
@@ -13,7 +13,6 @@ use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use servo_config::pref;
use wgpu::adapter_get_info;
-use wgpu::TypedId;
#[derive(Debug, Deserialize, Serialize)]
pub enum WebGPUResponse {
@@ -25,7 +24,11 @@ pub type WebGPUResponseResult = Result<WebGPUResponse, String>;
#[derive(Debug, Deserialize, Serialize)]
pub enum WebGPURequest {
- RequestAdapter(IpcSender<WebGPUResponseResult>, wgpu::RequestAdapterOptions),
+ RequestAdapter(
+ IpcSender<WebGPUResponseResult>,
+ wgpu::RequestAdapterOptions,
+ wgpu::AdapterId,
+ ),
RequestDevice,
Exit(IpcSender<()>),
}
@@ -93,17 +96,8 @@ impl WGPU {
fn run(mut self) {
while let Ok(msg) = self.receiver.recv() {
match msg {
- WebGPURequest::RequestAdapter(sender, options) => {
- let adapter_id = match wgpu::request_adapter(
- &self.global,
- &options,
- // TODO: The ids we pass here should be generated by the client
- &[
- wgpu::Id::zip(0, 0, wgpu::Backend::Vulkan),
- wgpu::Id::zip(0, 0, wgpu::Backend::Metal),
- wgpu::Id::zip(0, 0, wgpu::Backend::Dx12),
- ],
- ) {
+ WebGPURequest::RequestAdapter(sender, options, id) => {
+ let adapter_id = match wgpu::request_adapter(&self.global, &options, &[id]) {
Some(id) => id,
None => {
if let Err(e) =