mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2025-02-18 10:02:29 +00:00
Merge pull request #311 from tomaka/device-errors
Add more errors to DeviceCreationError
This commit is contained in:
commit
dd38355ec2
@ -155,10 +155,7 @@ impl Device {
|
|||||||
///
|
///
|
||||||
/// # Panic
|
/// # Panic
|
||||||
///
|
///
|
||||||
/// - Panics if one of the requested features is not supported by the physical device.
|
|
||||||
/// - Panics if one of the queue families doesn't belong to the given device.
|
/// - Panics if one of the queue families doesn't belong to the given device.
|
||||||
/// - Panics if you request more queues from a family than available.
|
|
||||||
/// - Panics if one of the priorities is outside of the `[0.0 ; 1.0]` range.
|
|
||||||
///
|
///
|
||||||
// TODO: return Arc<Queue> and handle synchronization in the Queue
|
// TODO: return Arc<Queue> and handle synchronization in the Queue
|
||||||
// TODO: should take the PhysicalDevice by value
|
// TODO: should take the PhysicalDevice by value
|
||||||
@ -169,7 +166,9 @@ impl Device {
|
|||||||
{
|
{
|
||||||
let queue_families = queue_families.into_iter();
|
let queue_families = queue_families.into_iter();
|
||||||
|
|
||||||
assert!(phys.supported_features().superset_of(&requested_features));
|
if !phys.supported_features().superset_of(&requested_features) {
|
||||||
|
return Err(DeviceCreationError::UnsupportedFeatures);
|
||||||
|
}
|
||||||
|
|
||||||
let vk_i = phys.instance().pointers();
|
let vk_i = phys.instance().pointers();
|
||||||
|
|
||||||
@ -204,7 +203,9 @@ impl Device {
|
|||||||
// checking the parameters
|
// checking the parameters
|
||||||
assert_eq!(queue_family.physical_device().internal_object(),
|
assert_eq!(queue_family.physical_device().internal_object(),
|
||||||
phys.internal_object());
|
phys.internal_object());
|
||||||
assert!(priority >= 0.0 && priority <= 1.0);
|
if priority < 0.0 || priority > 1.0 {
|
||||||
|
return Err(DeviceCreationError::PriorityOutOfRange);
|
||||||
|
}
|
||||||
|
|
||||||
// adding to `queues` and `output_queues`
|
// adding to `queues` and `output_queues`
|
||||||
if let Some(q) = queues.iter_mut().find(|q| q.0 == queue_family.id()) {
|
if let Some(q) = queues.iter_mut().find(|q| q.0 == queue_family.id()) {
|
||||||
@ -472,7 +473,10 @@ pub enum DeviceCreationError {
|
|||||||
OutOfDeviceMemory,
|
OutOfDeviceMemory,
|
||||||
/// Tried to create too many queues for a given family.
|
/// Tried to create too many queues for a given family.
|
||||||
TooManyQueuesForFamily,
|
TooManyQueuesForFamily,
|
||||||
// FIXME: other values
|
/// Some of the requested features are unsupported by the physical device.
|
||||||
|
UnsupportedFeatures,
|
||||||
|
/// The priority of one of the queues is out of the [0.0; 1.0] range.
|
||||||
|
PriorityOutOfRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl error::Error for DeviceCreationError {
|
impl error::Error for DeviceCreationError {
|
||||||
@ -486,6 +490,12 @@ impl error::Error for DeviceCreationError {
|
|||||||
DeviceCreationError::TooManyQueuesForFamily => {
|
DeviceCreationError::TooManyQueuesForFamily => {
|
||||||
"tried to create too many queues for a given family"
|
"tried to create too many queues for a given family"
|
||||||
},
|
},
|
||||||
|
DeviceCreationError::UnsupportedFeatures => {
|
||||||
|
"some of the requested features are unsupported by the physical device"
|
||||||
|
},
|
||||||
|
DeviceCreationError::PriorityOutOfRange => {
|
||||||
|
"the priority of one of the queues is out of the [0.0; 1.0] range"
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -632,4 +642,51 @@ mod tests {
|
|||||||
_ => panic!()
|
_ => panic!()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unsupposed_features() {
|
||||||
|
let instance = instance!();
|
||||||
|
let physical = match instance::PhysicalDevice::enumerate(&instance).next() {
|
||||||
|
Some(p) => p,
|
||||||
|
None => return
|
||||||
|
};
|
||||||
|
|
||||||
|
let family = physical.queue_families().next().unwrap();
|
||||||
|
|
||||||
|
let features = Features::all();
|
||||||
|
// In the unlikely situation where the device supports everything, we ignore the test.
|
||||||
|
if physical.supported_features().superset_of(&features) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
match Device::new(&physical, &features, &DeviceExtensions::none(), Some((family, 1.0))) {
|
||||||
|
Err(DeviceCreationError::UnsupportedFeatures) => return, // Success
|
||||||
|
_ => panic!()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn priority_out_of_range() {
|
||||||
|
let instance = instance!();
|
||||||
|
let physical = match instance::PhysicalDevice::enumerate(&instance).next() {
|
||||||
|
Some(p) => p,
|
||||||
|
None => return
|
||||||
|
};
|
||||||
|
|
||||||
|
let family = physical.queue_families().next().unwrap();
|
||||||
|
|
||||||
|
match Device::new(&physical, &Features::none(),
|
||||||
|
&DeviceExtensions::none(), Some((family, 1.4)))
|
||||||
|
{
|
||||||
|
Err(DeviceCreationError::PriorityOutOfRange) => (), // Success
|
||||||
|
_ => panic!()
|
||||||
|
};
|
||||||
|
|
||||||
|
match Device::new(&physical, &Features::none(),
|
||||||
|
&DeviceExtensions::none(), Some((family, -0.2)))
|
||||||
|
{
|
||||||
|
Err(DeviceCreationError::PriorityOutOfRange) => (), // Success
|
||||||
|
_ => panic!()
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,18 @@ macro_rules! features {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Builds a `Features` object with all values to true.
|
||||||
|
///
|
||||||
|
/// > **Note**: This function is used for testing purposes, and is probably useless in
|
||||||
|
/// > a real code.
|
||||||
|
pub fn all() -> Features {
|
||||||
|
Features {
|
||||||
|
$(
|
||||||
|
$name: true,
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if `self` is a superset of the parameter.
|
/// Returns true if `self` is a superset of the parameter.
|
||||||
///
|
///
|
||||||
/// That is, for each feature of the parameter that is true, the corresponding value
|
/// That is, for each feature of the parameter that is true, the corresponding value
|
||||||
|
Loading…
Reference in New Issue
Block a user