mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 00:03:29 +00:00
make Queue.device
non-optional
This commit is contained in:
parent
f34f7eb658
commit
6fe041d544
@ -37,8 +37,8 @@ use thiserror::Error;
|
||||
use super::Device;
|
||||
|
||||
pub struct Queue<A: HalApi> {
|
||||
pub(crate) device: Option<Arc<Device<A>>>,
|
||||
pub(crate) raw: Option<A::Queue>,
|
||||
pub(crate) device: Arc<Device<A>>,
|
||||
}
|
||||
|
||||
crate::impl_resource_type!(Queue);
|
||||
@ -48,19 +48,14 @@ impl<A: HalApi> Labeled for Queue<A> {
|
||||
""
|
||||
}
|
||||
}
|
||||
crate::impl_parent_device!(Queue);
|
||||
crate::impl_storage_item!(Queue);
|
||||
|
||||
impl<A: HalApi> ParentDevice<A> for Queue<A> {
|
||||
fn device(&self) -> &Arc<Device<A>> {
|
||||
self.device.as_ref().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: HalApi> Drop for Queue<A> {
|
||||
fn drop(&mut self) {
|
||||
resource_log!("Drop {}", self.error_ident());
|
||||
let queue = self.raw.take().unwrap();
|
||||
self.device.as_ref().unwrap().release_queue(queue);
|
||||
self.device.release_queue(queue);
|
||||
}
|
||||
}
|
||||
|
||||
@ -429,7 +424,7 @@ impl Global {
|
||||
.get(queue_id)
|
||||
.map_err(|_| QueueWriteError::InvalidQueueId)?;
|
||||
|
||||
let device = queue.device.as_ref().unwrap();
|
||||
let device = &queue.device;
|
||||
|
||||
let data_size = data.len() as wgt::BufferAddress;
|
||||
|
||||
@ -497,7 +492,7 @@ impl Global {
|
||||
.get(queue_id)
|
||||
.map_err(|_| QueueWriteError::InvalidQueueId)?;
|
||||
|
||||
let device = queue.device.as_ref().unwrap();
|
||||
let device = &queue.device;
|
||||
|
||||
let (staging_buffer, staging_buffer_ptr) =
|
||||
prepare_staging_buffer(device, buffer_size.get(), device.instance_flags)?;
|
||||
@ -524,7 +519,7 @@ impl Global {
|
||||
.get(queue_id)
|
||||
.map_err(|_| QueueWriteError::InvalidQueueId)?;
|
||||
|
||||
let device = queue.device.as_ref().unwrap();
|
||||
let device = &queue.device;
|
||||
|
||||
let staging_buffer = hub.staging_buffers.unregister(staging_buffer_id);
|
||||
if staging_buffer.is_none() {
|
||||
@ -692,7 +687,7 @@ impl Global {
|
||||
.get(queue_id)
|
||||
.map_err(|_| QueueWriteError::InvalidQueueId)?;
|
||||
|
||||
let device = queue.device.as_ref().unwrap();
|
||||
let device = &queue.device;
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
if let Some(ref mut trace) = *device.trace.lock() {
|
||||
@ -950,7 +945,7 @@ impl Global {
|
||||
.get(queue_id)
|
||||
.map_err(|_| QueueWriteError::InvalidQueueId)?;
|
||||
|
||||
let device = queue.device.as_ref().unwrap();
|
||||
let device = &queue.device;
|
||||
|
||||
if size.width == 0 || size.height == 0 || size.depth_or_array_layers == 0 {
|
||||
log::trace!("Ignoring write_texture of size 0");
|
||||
@ -1144,7 +1139,7 @@ impl Global {
|
||||
.get(queue_id)
|
||||
.map_err(|_| QueueSubmitError::InvalidQueueId)?;
|
||||
|
||||
let device = queue.device.as_ref().unwrap();
|
||||
let device = &queue.device;
|
||||
|
||||
let snatch_guard = device.snatchable_lock.read();
|
||||
|
||||
@ -1551,12 +1546,7 @@ impl Global {
|
||||
//TODO: flush pending writes
|
||||
let hub = A::hub(self);
|
||||
match hub.queues.get(queue_id) {
|
||||
Ok(queue) => queue
|
||||
.device
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.lock_life()
|
||||
.add_work_done_closure(closure),
|
||||
Ok(queue) => queue.device.lock_life().add_work_done_closure(closure),
|
||||
Err(_) => return Err(InvalidQueue),
|
||||
}
|
||||
Ok(())
|
||||
|
@ -284,7 +284,7 @@ impl<A: HalApi> Adapter<A> {
|
||||
desc: &DeviceDescriptor,
|
||||
instance_flags: wgt::InstanceFlags,
|
||||
trace_path: Option<&std::path::Path>,
|
||||
) -> Result<(Device<A>, Queue<A>), RequestDeviceError> {
|
||||
) -> Result<(Arc<Device<A>>, Queue<A>), RequestDeviceError> {
|
||||
api_log!("Adapter::create_device");
|
||||
|
||||
if let Ok(device) = Device::new(
|
||||
@ -295,8 +295,9 @@ impl<A: HalApi> Adapter<A> {
|
||||
trace_path,
|
||||
instance_flags,
|
||||
) {
|
||||
let device = Arc::new(device);
|
||||
let queue = Queue {
|
||||
device: None,
|
||||
device: device.clone(),
|
||||
raw: Some(hal_device.queue),
|
||||
};
|
||||
return Ok((device, queue));
|
||||
@ -309,7 +310,7 @@ impl<A: HalApi> Adapter<A> {
|
||||
desc: &DeviceDescriptor,
|
||||
instance_flags: wgt::InstanceFlags,
|
||||
trace_path: Option<&std::path::Path>,
|
||||
) -> Result<(Device<A>, Queue<A>), RequestDeviceError> {
|
||||
) -> Result<(Arc<Device<A>>, Queue<A>), RequestDeviceError> {
|
||||
// Verify all features were exposed by the adapter
|
||||
if !self.raw.features.contains(desc.required_features) {
|
||||
return Err(RequestDeviceError::UnsupportedFeature(
|
||||
@ -1084,16 +1085,15 @@ impl Global {
|
||||
Ok(adapter) => adapter,
|
||||
Err(_) => break 'error RequestDeviceError::InvalidAdapter,
|
||||
};
|
||||
let (device, mut queue) =
|
||||
let (device, queue) =
|
||||
match adapter.create_device_and_queue(desc, self.instance.flags, trace_path) {
|
||||
Ok((device, queue)) => (device, queue),
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
let (device_id, _) = device_fid.assign(Arc::new(device));
|
||||
let (device_id, _) = device_fid.assign(device);
|
||||
resource_log!("Created Device {:?}", device_id);
|
||||
|
||||
let device = hub.devices.get(device_id).unwrap();
|
||||
queue.device = Some(device.clone());
|
||||
|
||||
let (queue_id, queue) = queue_fid.assign(Arc::new(queue));
|
||||
resource_log!("Created Queue {:?}", queue_id);
|
||||
@ -1132,7 +1132,7 @@ impl Global {
|
||||
Ok(adapter) => adapter,
|
||||
Err(_) => break 'error RequestDeviceError::InvalidAdapter,
|
||||
};
|
||||
let (device, mut queue) = match adapter.create_device_and_queue_from_hal(
|
||||
let (device, queue) = match adapter.create_device_and_queue_from_hal(
|
||||
hal_device,
|
||||
desc,
|
||||
self.instance.flags,
|
||||
@ -1141,11 +1141,10 @@ impl Global {
|
||||
Ok(device) => device,
|
||||
Err(e) => break 'error e,
|
||||
};
|
||||
let (device_id, _) = devices_fid.assign(Arc::new(device));
|
||||
let (device_id, _) = devices_fid.assign(device);
|
||||
resource_log!("Created Device {:?}", device_id);
|
||||
|
||||
let device = hub.devices.get(device_id).unwrap();
|
||||
queue.device = Some(device.clone());
|
||||
|
||||
let (queue_id, queue) = queues_fid.assign(Arc::new(queue));
|
||||
resource_log!("Created Queue {:?}", queue_id);
|
||||
|
Loading…
Reference in New Issue
Block a user