mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 23:04:07 +00:00
Validate device descriptor before opening (#2159)
This commit is contained in:
parent
2755cd08eb
commit
693bc58bdd
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user