diff --git a/player/src/main.rs b/player/src/main.rs index f5e1b437e..ef42c883b 100644 --- a/player/src/main.rs +++ b/player/src/main.rs @@ -507,10 +507,10 @@ fn main() { None, wgc::id::TypedId::zip(1, 0, wgt::Backend::Empty) )) + .expect("Failed to request device") } _ => panic!("Expected Action::Init"), }; - log::info!("Executing actions"); #[cfg(not(feature = "winit"))] { diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 7c4113cea..7aba21026 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -23,6 +23,7 @@ use hal::{ window::Surface as _, Instance as _, }; +use std::fmt::Display; #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -217,6 +218,30 @@ impl AdapterInfo { } } +#[derive(Clone, Debug, PartialEq)] +/// Error when requesting a device from the adaptor +pub enum RequestDeviceError { + /// Unsupported feature extension was requested + UnsupportedFeature(wgt::Features), + /// Requested device limits were exceeded + LimitsExceeded, +} + +impl Display for RequestDeviceError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match &self { + RequestDeviceError::UnsupportedFeature(features) => write!( + f, + "Cannot enable features that adapter doesn't support. Unsupported extensions: {:?}", + features + ), + RequestDeviceError::LimitsExceeded => { + write!(f, "Some of the requested limits are not supported",) + } + } + } +} + /// Supported physical device types. #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "trace", derive(Serialize))] @@ -550,7 +575,7 @@ impl Global { desc: &DeviceDescriptor, trace_path: Option<&std::path::Path>, id_in: Input, - ) -> DeviceId { + ) -> Result { span!(_guard, INFO, "Adapter::request_device"); let hub = B::hub(self); @@ -568,11 +593,11 @@ impl Global { desc.features & wgt::Features::ALL_UNSAFE ) } - assert!( - adapter.features.contains(desc.features), - "Cannot enable features that adapter doesn't support. Unsupported extensions: {:?}", - desc.features - adapter.features - ); + if !adapter.features.contains(desc.features) { + return Err(RequestDeviceError::UnsupportedFeature( + desc.features - adapter.features, + )); + } // Verify feature preconditions if desc @@ -665,10 +690,9 @@ impl Global { if limits.max_bound_descriptor_sets == 0 { log::warn!("max_bind_groups limit is missing"); } else { - assert!( - desc.limits.max_bind_groups <= adapter.limits.max_bind_groups, - "Adapter does not support the requested max_bind_groups" - ); + if adapter.limits.max_bind_groups < desc.limits.max_bind_groups { + return Err(RequestDeviceError::LimitsExceeded); + } } let mem_props = phd.memory_properties(); @@ -699,6 +723,6 @@ impl Global { ) }; - hub.devices.register_identity(id_in, device, &mut token) + Ok(hub.devices.register_identity(id_in, device, &mut token)) } }