aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/gpu.rs16
-rw-r--r--components/script/dom/gpuadapter.rs10
-rw-r--r--components/script/dom/identityhub.rs93
-rw-r--r--components/script/dom/navigator.rs14
4 files changed, 96 insertions, 37 deletions
diff --git a/components/script/dom/gpu.rs b/components/script/dom/gpu.rs
index 4e47620052e..8a3e05f2d79 100644
--- a/components/script/dom/gpu.rs
+++ b/components/script/dom/gpu.rs
@@ -117,11 +117,13 @@ impl GPUMethods for GPU {
let promise = Promise::new_in_current_compartment(&self.global(), comp);
let sender = response_async(&promise, self);
let power_preference = match options.powerPreference {
- Some(GPUPowerPreference::Low_power) => wgpu::PowerPreference::LowPower,
- Some(GPUPowerPreference::High_performance) => wgpu::PowerPreference::HighPerformance,
- None => wgpu::PowerPreference::Default,
+ Some(GPUPowerPreference::Low_power) => wgpu::instance::PowerPreference::LowPower,
+ Some(GPUPowerPreference::High_performance) => {
+ wgpu::instance::PowerPreference::HighPerformance
+ },
+ None => wgpu::instance::PowerPreference::Default,
};
- let id = self.global().as_window().Navigator().create_adapter_id();
+ let ids = self.global().as_window().Navigator().create_adapter_ids();
match self.wgpu_channel() {
Some(channel) => {
@@ -129,8 +131,8 @@ impl GPUMethods for GPU {
.0
.send(WebGPURequest::RequestAdapter(
sender,
- wgpu::RequestAdapterOptions { power_preference },
- id,
+ wgpu::instance::RequestAdapterOptions { power_preference },
+ ids,
))
.unwrap();
},
@@ -146,7 +148,7 @@ impl AsyncWGPUListener for GPU {
WebGPUResponse::RequestAdapter(name, adapter) => {
let adapter = GPUAdapter::new(
&self.global(),
- DOMString::from(name),
+ DOMString::from(format!("{} ({:?})", name, adapter.0.backend())),
Heap::default(),
adapter,
);
diff --git a/components/script/dom/gpuadapter.rs b/components/script/dom/gpuadapter.rs
index 34b6fc38d45..937b9103321 100644
--- a/components/script/dom/gpuadapter.rs
+++ b/components/script/dom/gpuadapter.rs
@@ -78,16 +78,18 @@ impl GPUAdapterMethods for GPUAdapter {
fn RequestDevice(&self, descriptor: &GPUDeviceDescriptor, comp: InCompartment) -> Rc<Promise> {
let promise = Promise::new_in_current_compartment(&self.global(), comp);
let sender = response_async(&promise, self);
- let desc = wgpu::DeviceDescriptor {
- extensions: wgpu::Extensions {
+ let desc = wgpu::instance::DeviceDescriptor {
+ extensions: wgpu::instance::Extensions {
anisotropic_filtering: descriptor.extensions.anisotropicFiltering,
},
- limits: wgpu::Limits {
+ limits: wgpu::instance::Limits {
max_bind_groups: descriptor.limits.maxBindGroups,
},
};
if let Some(window) = self.global().downcast::<Window>() {
- let id = window.Navigator().create_device_id();
+ let id = window
+ .Navigator()
+ .create_device_id(self.adapter.0.backend());
match window.webgpu_channel() {
Some(thread) => thread
.0
diff --git a/components/script/dom/identityhub.rs b/components/script/dom/identityhub.rs
index 6c79a3c5f46..b2f310330e9 100644
--- a/components/script/dom/identityhub.rs
+++ b/components/script/dom/identityhub.rs
@@ -2,50 +2,101 @@
* 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};
+use smallvec::SmallVec;
+use webgpu::wgpu::{
+ hub::IdentityManager,
+ id::{AdapterId, DeviceId},
+ Backend,
+};
#[derive(Debug)]
pub struct IdentityHub {
- adapters: IdentityManager<AdapterId>,
- devices: IdentityManager<DeviceId>,
+ adapters: IdentityManager,
+ devices: IdentityManager,
+ backend: Backend,
}
impl IdentityHub {
fn new(backend: Backend) -> Self {
IdentityHub {
- adapters: IdentityManager::new(backend),
- devices: IdentityManager::new(backend),
+ adapters: IdentityManager::default(),
+ devices: IdentityManager::default(),
+ backend,
}
}
+
+ fn create_adapter_id(&mut self) -> AdapterId {
+ self.adapters.alloc(self.backend)
+ }
+
+ fn create_device_id(&mut self) -> DeviceId {
+ self.devices.alloc(self.backend)
+ }
}
#[derive(Debug)]
pub struct Identities {
- surface: IdentityManager<SurfaceId>,
- hub: IdentityHub,
+ surface: IdentityManager,
+ #[cfg(any(target_os = "linux", target_os = "windows"))]
+ vk_hub: IdentityHub,
+ #[cfg(target_os = "windows")]
+ dx12_hub: IdentityHub,
+ #[cfg(target_os = "windows")]
+ dx11_hub: IdentityHub,
+ #[cfg(any(target_os = "ios", target_os = "macos"))]
+ metal_hub: IdentityHub,
+ dummy_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,
+ surface: IdentityManager::default(),
+ #[cfg(any(target_os = "linux", target_os = "windows"))]
+ vk_hub: IdentityHub::new(Backend::Vulkan),
+ #[cfg(target_os = "windows")]
+ dx12_hub: IdentityHub::new(Backend::Dx12),
+ #[cfg(target_os = "windows")]
+ dx11_hub: IdentityHub::new(Backend::Dx11),
+ #[cfg(any(target_os = "ios", target_os = "macos"))]
+ metal_hub: IdentityHub::new(Backend::Metal),
+ dummy_hub: IdentityHub::new(Backend::Empty),
}
}
- pub fn create_adapter_id(&mut self) -> AdapterId {
- self.hub.adapters.alloc()
+ fn hubs(&mut self) -> Vec<&mut IdentityHub> {
+ vec![
+ #[cfg(any(target_os = "linux", target_os = "windows"))]
+ &mut self.vk_hub,
+ #[cfg(target_os = "windows")]
+ &mut self.dx12_hub,
+ #[cfg(target_os = "windows")]
+ &mut self.dx11_hub,
+ #[cfg(any(target_os = "ios", target_os = "macos"))]
+ &mut self.metal_hub,
+ &mut self.dummy_hub,
+ ]
}
- pub fn create_device_id(&mut self) -> DeviceId {
- self.hub.devices.alloc()
+ pub fn create_device_id(&mut self, backend: Backend) -> DeviceId {
+ match backend {
+ #[cfg(any(target_os = "linux", target_os = "windows"))]
+ Backend::Vulkan => self.vk_hub.create_device_id(),
+ #[cfg(target_os = "windows")]
+ Backend::Dx12 => self.dx12_hub.create_device_id(),
+ #[cfg(target_os = "windows")]
+ Backend::Dx11 => self.dx11_hub.create_device_id(),
+ #[cfg(any(target_os = "ios", target_os = "macos"))]
+ Backend::Metal => self.metal_hub.create_device_id(),
+ _ => self.dummy_hub.create_device_id(),
+ }
+ }
+
+ pub fn create_adapter_ids(&mut self) -> SmallVec<[AdapterId; 4]> {
+ let mut ids = SmallVec::new();
+ for hub in self.hubs() {
+ ids.push(hub.create_adapter_id())
+ }
+ ids
}
}
diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs
index c813af4ea99..491ae034f31 100644
--- a/components/script/dom/navigator.rs
+++ b/components/script/dom/navigator.rs
@@ -24,9 +24,13 @@ use crate::dom::serviceworkercontainer::ServiceWorkerContainer;
use crate::dom::window::Window;
use crate::dom::xr::XR;
use dom_struct::dom_struct;
+use smallvec::SmallVec;
use std::cell::RefCell;
use std::rc::Rc;
-use webgpu::wgpu::{AdapterId, DeviceId};
+use webgpu::wgpu::{
+ id::{AdapterId, DeviceId},
+ Backend,
+};
#[dom_struct]
pub struct Navigator {
@@ -73,12 +77,12 @@ impl Navigator {
}
impl Navigator {
- pub fn create_adapter_id(&self) -> AdapterId {
- self.gpu_id_hub.borrow_mut().create_adapter_id()
+ pub fn create_adapter_ids(&self) -> SmallVec<[AdapterId; 4]> {
+ self.gpu_id_hub.borrow_mut().create_adapter_ids()
}
- pub fn create_device_id(&self) -> DeviceId {
- self.gpu_id_hub.borrow_mut().create_device_id()
+ pub fn create_device_id(&self, backend: Backend) -> DeviceId {
+ self.gpu_id_hub.borrow_mut().create_device_id(backend)
}
}