From cd8e2a30b2f1dd5cd029dbfa1d42e07dcd3cb58b Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sun, 26 Jan 2020 23:09:58 +0100 Subject: [PATCH] Duplicate `DeviceType` from `gfx-hal`. --- wgpu-core/src/instance.rs | 38 +++++++++++++++++++++++++++++++++----- wgpu-core/src/lib.rs | 4 ++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 52d1ad1f01..b23ddd0e3e 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -15,10 +15,9 @@ use crate::{ #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -pub use hal::adapter::DeviceType; use hal::{ self, - adapter::{AdapterInfo as GfxAdapterInfo, PhysicalDevice as _}, + adapter::{AdapterInfo as HalAdapterInfo, DeviceType as HalDeviceType, PhysicalDevice as _}, queue::QueueFamily as _, Instance as _, }; @@ -182,6 +181,7 @@ impl From for BackendBit { /// Metadata about a backend adapter. #[derive(Clone, Debug, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct AdapterInfo { /// Adapter name pub name: String, @@ -196,8 +196,8 @@ pub struct AdapterInfo { } impl AdapterInfo { - fn from_gfx(adapter_info: GfxAdapterInfo, backend: Backend) -> Self { - let GfxAdapterInfo { + fn from_gfx(adapter_info: HalAdapterInfo, backend: Backend) -> Self { + let HalAdapterInfo { name, vendor, device, @@ -208,12 +208,40 @@ impl AdapterInfo { name, vendor, device, - device_type, + device_type: device_type.into(), backend, } } } +/// Supported physical device types +#[derive(Clone, Debug, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub enum DeviceType { + /// Other + Other, + /// Integrated + IntegratedGpu, + /// Discrete + 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() -> I), diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index d6e2fc9208..047a1e7c03 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -30,6 +30,9 @@ pub mod resource; pub mod swap_chain; pub mod track; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + pub use hal::pso::read_spirv; use peek_poke::{PeekCopy, Poke}; @@ -45,6 +48,7 @@ type Epoch = u32; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum Backend { Empty = 0, Vulkan = 1,