mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Replace wgpu-native with wgpu-core
This commit is contained in:
parent
250184fe60
commit
e146e6058a
8 changed files with 130 additions and 59 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue