Validate device descriptor before opening (#2159)

This commit is contained in:
Dzmitry Malyshau 2021-11-06 17:09:52 -04:00 committed by GitHub
parent 2755cd08eb
commit 693bc58bdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -279,6 +279,27 @@ impl<A: HalApi> Adapter<A> {
open: hal::OpenDevice<A>,
desc: &DeviceDescriptor,
trace_path: Option<&std::path::Path>,
) -> Result<Device<A>, RequestDeviceError> {
let caps = &self.raw.capabilities;
Device::new(
open,
Stored {
value: Valid(self_id),
ref_count: self.life_guard.add_ref(),
},
caps.alignments.clone(),
caps.downlevel.clone(),
desc,
trace_path,
)
.or(Err(RequestDeviceError::OutOfMemory))
}
fn create_device(
&self,
self_id: AdapterId,
desc: &DeviceDescriptor,
trace_path: Option<&std::path::Path>,
) -> Result<Device<A>, RequestDeviceError> {
// Verify all features were exposed by the adapter
if !self.raw.features.contains(desc.features) {
@ -317,26 +338,6 @@ impl<A: HalApi> Adapter<A> {
return Err(RequestDeviceError::LimitsExceeded(failed));
}
Device::new(
open,
Stored {
value: Valid(self_id),
ref_count: self.life_guard.add_ref(),
},
caps.alignments.clone(),
caps.downlevel.clone(),
desc,
trace_path,
)
.or(Err(RequestDeviceError::OutOfMemory))
}
fn create_device(
&self,
self_id: AdapterId,
desc: &DeviceDescriptor,
trace_path: Option<&std::path::Path>,
) -> Result<Device<A>, RequestDeviceError> {
let open = unsafe { self.raw.adapter.open(desc.features, &desc.limits) }.map_err(
|err| match err {
hal::DeviceError::Lost => RequestDeviceError::DeviceLost,