diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index d7cdbaae1a..121740737d 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -9,6 +9,27 @@ use crate::{ use std::convert::TryInto; +pub fn map_adapter_info( + info: hal::adapter::AdapterInfo, + backend: wgt::Backend, +) -> wgt::AdapterInfo { + use hal::adapter::DeviceType as Dt; + + wgt::AdapterInfo { + name: info.name, + vendor: info.vendor, + device: info.device, + device_type: match info.device_type { + Dt::Other => wgt::DeviceType::Other, + Dt::IntegratedGpu => wgt::DeviceType::IntegratedGpu, + Dt::DiscreteGpu => wgt::DeviceType::DiscreteGpu, + Dt::VirtualGpu => wgt::DeviceType::VirtualGpu, + Dt::Cpu => wgt::DeviceType::Cpu, + }, + backend, + } +} + pub fn map_buffer_usage(usage: wgt::BufferUsage) -> (hal::buffer::Usage, hal::memory::Properties) { use hal::buffer::Usage as U; use hal::memory::Properties as P; diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 52d9be0276..bc50956d83 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use crate::{ - backend, + backend, conv, device::{Device, DeviceDescriptor}, hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token}, id::{AdapterId, DeviceId, SurfaceId, Valid}, @@ -13,10 +13,7 @@ use crate::{ use wgt::{Backend, BackendBit, PowerPreference, BIND_BUFFER_ALIGNMENT}; use hal::{ - adapter::{AdapterInfo as HalAdapterInfo, DeviceType as HalDeviceType, PhysicalDevice as _}, - queue::QueueFamily as _, - window::Surface as _, - Instance as _, + adapter::PhysicalDevice as _, queue::QueueFamily as _, window::Surface as _, Instance as _, }; use thiserror::Error; @@ -400,42 +397,6 @@ impl crate::hub::Resource for Adapter { } } -/// Metadata about a backend adapter. -#[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] -pub struct AdapterInfo { - /// Adapter name - pub name: String, - /// Vendor PCI id of the adapter - pub vendor: usize, - /// PCI id of the adapter - pub device: usize, - /// Type of device - pub device_type: DeviceType, - /// Backend used for device - pub backend: Backend, -} - -impl AdapterInfo { - fn from_gfx(adapter_info: HalAdapterInfo, backend: Backend) -> Self { - let HalAdapterInfo { - name, - vendor, - device, - device_type, - } = adapter_info; - - Self { - name, - vendor, - device, - device_type: device_type.into(), - backend, - } - } -} - #[derive(Clone, Debug, Error)] /// Error when requesting a device from the adaptor pub enum RequestDeviceError { @@ -455,36 +416,6 @@ pub enum RequestDeviceError { UnsupportedFeature(wgt::Features), } -/// Supported physical device types. -#[repr(u8)] -#[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "trace", derive(serde::Serialize))] -#[cfg_attr(feature = "replay", derive(serde::Deserialize))] -pub enum DeviceType { - /// Other. - Other, - /// Integrated GPU with shared CPU/GPU memory. - IntegratedGpu, - /// Discrete GPU with separate CPU/GPU memory. - DiscreteGpu, - /// Virtual / Hosted. - VirtualGpu, - /// Cpu / Software Rendering. - Cpu, -} - -impl From for DeviceType { - fn from(device_type: HalDeviceType) -> Self { - match device_type { - HalDeviceType::Other => Self::Other, - HalDeviceType::IntegratedGpu => Self::IntegratedGpu, - HalDeviceType::DiscreteGpu => Self::DiscreteGpu, - HalDeviceType::VirtualGpu => Self::VirtualGpu, - HalDeviceType::Cpu => Self::Cpu, - } - } -} - pub enum AdapterInputs<'a, I> { IdSet(&'a [I], fn(&I) -> Backend), Mask(BackendBit, fn(Backend) -> I), @@ -761,7 +692,7 @@ impl Global { pub fn adapter_get_info( &self, adapter_id: AdapterId, - ) -> Result { + ) -> Result { span!(_guard, INFO, "Adapter::get_info"); let hub = B::hub(self); @@ -769,7 +700,7 @@ impl Global { let (adapter_guard, _) = hub.adapters.read(&mut token); adapter_guard .get(adapter_id) - .map(|adapter| AdapterInfo::from_gfx(adapter.raw.info.clone(), adapter_id.backend())) + .map(|adapter| conv::map_adapter_info(adapter.raw.info.clone(), adapter_id.backend())) .map_err(|_| InvalidAdapter) } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 49071979d6..3910c2fc8e 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -401,6 +401,41 @@ impl Default for Limits { } } +/// Supported physical device types. +#[repr(u8)] +#[derive(Clone, Debug, PartialEq)] +#[cfg_attr(feature = "trace", derive(serde::Serialize))] +#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +pub enum DeviceType { + /// Other. + Other, + /// Integrated GPU with shared CPU/GPU memory. + IntegratedGpu, + /// Discrete GPU with separate CPU/GPU memory. + DiscreteGpu, + /// Virtual / Hosted. + VirtualGpu, + /// Cpu / Software Rendering. + Cpu, +} + +/// Information about an adapter. +#[derive(Clone, Debug, PartialEq)] +#[cfg_attr(feature = "trace", derive(serde::Serialize))] +#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +pub struct AdapterInfo { + /// Adapter name + pub name: String, + /// Vendor PCI id of the adapter + pub vendor: usize, + /// PCI id of the adapter + pub device: usize, + /// Type of device + pub device_type: DeviceType, + /// Backend used for device + pub backend: Backend, +} + /// Describes a [`Device`]. #[repr(C)] #[derive(Clone, Debug, Default)]