mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
remove Registry.try_get()
This commit is contained in:
parent
b904e2c759
commit
16c7d84d63
@ -112,9 +112,6 @@ impl<T: StorageItem> Registry<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn try_get(&self, id: Id<T::Marker>) -> Result<Option<Arc<T>>, InvalidId> {
|
||||
self.read().try_get(id).map(|o| o.cloned())
|
||||
}
|
||||
pub(crate) fn get(&self, id: Id<T::Marker>) -> Result<Arc<T>, InvalidId> {
|
||||
self.read().get_owned(id)
|
||||
}
|
||||
|
@ -1149,13 +1149,14 @@ impl Global {
|
||||
profiling::scope!("Buffer::as_hal");
|
||||
|
||||
let hub = A::hub(self);
|
||||
let buffer_opt = { hub.buffers.try_get(id).ok().flatten() };
|
||||
let buffer = buffer_opt.as_ref().unwrap();
|
||||
|
||||
let snatch_guard = buffer.device.snatchable_lock.read();
|
||||
let hal_buffer = buffer.raw(&snatch_guard);
|
||||
|
||||
hal_buffer_callback(hal_buffer)
|
||||
if let Ok(buffer) = hub.buffers.get(id) {
|
||||
let snatch_guard = buffer.device.snatchable_lock.read();
|
||||
let hal_buffer = buffer.raw(&snatch_guard);
|
||||
hal_buffer_callback(hal_buffer)
|
||||
} else {
|
||||
hal_buffer_callback(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
@ -1169,12 +1170,14 @@ impl Global {
|
||||
profiling::scope!("Texture::as_hal");
|
||||
|
||||
let hub = A::hub(self);
|
||||
let texture_opt = { hub.textures.try_get(id).ok().flatten() };
|
||||
let texture = texture_opt.as_ref().unwrap();
|
||||
let snatch_guard = texture.device.snatchable_lock.read();
|
||||
let hal_texture = texture.raw(&snatch_guard);
|
||||
|
||||
hal_texture_callback(hal_texture)
|
||||
if let Ok(texture) = hub.textures.get(id) {
|
||||
let snatch_guard = texture.device.snatchable_lock.read();
|
||||
let hal_texture = texture.raw(&snatch_guard);
|
||||
hal_texture_callback(hal_texture)
|
||||
} else {
|
||||
hal_texture_callback(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
@ -1188,12 +1191,14 @@ impl Global {
|
||||
profiling::scope!("TextureView::as_hal");
|
||||
|
||||
let hub = A::hub(self);
|
||||
let texture_view_opt = { hub.texture_views.try_get(id).ok().flatten() };
|
||||
let texture_view = texture_view_opt.as_ref().unwrap();
|
||||
let snatch_guard = texture_view.device.snatchable_lock.read();
|
||||
let hal_texture_view = texture_view.raw(&snatch_guard);
|
||||
|
||||
hal_texture_view_callback(hal_texture_view)
|
||||
if let Ok(texture_view) = hub.texture_views.get(id) {
|
||||
let snatch_guard = texture_view.device.snatchable_lock.read();
|
||||
let hal_texture_view = texture_view.raw(&snatch_guard);
|
||||
hal_texture_view_callback(hal_texture_view)
|
||||
} else {
|
||||
hal_texture_view_callback(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
@ -1207,7 +1212,7 @@ impl Global {
|
||||
profiling::scope!("Adapter::as_hal");
|
||||
|
||||
let hub = A::hub(self);
|
||||
let adapter = hub.adapters.try_get(id).ok().flatten();
|
||||
let adapter = hub.adapters.get(id).ok();
|
||||
let hal_adapter = adapter.as_ref().map(|adapter| &adapter.raw.adapter);
|
||||
|
||||
hal_adapter_callback(hal_adapter)
|
||||
@ -1224,7 +1229,7 @@ impl Global {
|
||||
profiling::scope!("Device::as_hal");
|
||||
|
||||
let hub = A::hub(self);
|
||||
let device = hub.devices.try_get(id).ok().flatten();
|
||||
let device = hub.devices.get(id).ok();
|
||||
let hal_device = device.as_ref().map(|device| device.raw());
|
||||
|
||||
hal_device_callback(hal_device)
|
||||
@ -1241,10 +1246,14 @@ impl Global {
|
||||
profiling::scope!("Device::fence_as_hal");
|
||||
|
||||
let hub = A::hub(self);
|
||||
let device = hub.devices.try_get(id).ok().flatten();
|
||||
let hal_fence = device.as_ref().map(|device| device.fence.read());
|
||||
|
||||
hal_fence_callback(hal_fence.as_deref().unwrap().as_ref())
|
||||
if let Ok(device) = hub.devices.get(id) {
|
||||
let hal_fence = device.fence.read();
|
||||
let hal_fence = hal_fence.as_ref();
|
||||
hal_fence_callback(hal_fence)
|
||||
} else {
|
||||
hal_fence_callback(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
@ -1279,15 +1288,15 @@ impl Global {
|
||||
profiling::scope!("CommandEncoder::as_hal");
|
||||
|
||||
let hub = A::hub(self);
|
||||
let cmd_buf = hub
|
||||
.command_buffers
|
||||
.get(id.into_command_buffer_id())
|
||||
.unwrap();
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.as_mut().unwrap();
|
||||
let cmd_buf_raw = cmd_buf_data.encoder.open().ok();
|
||||
|
||||
hal_command_encoder_callback(cmd_buf_raw)
|
||||
if let Ok(cmd_buf) = hub.command_buffers.get(id.into_command_buffer_id()) {
|
||||
let mut cmd_buf_data = cmd_buf.data.lock();
|
||||
let cmd_buf_data = cmd_buf_data.as_mut().unwrap();
|
||||
let cmd_buf_raw = cmd_buf_data.encoder.open().ok();
|
||||
hal_command_encoder_callback(cmd_buf_raw)
|
||||
} else {
|
||||
hal_command_encoder_callback(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,29 +92,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to get a reference to an item behind a potentially invalid ID.
|
||||
///
|
||||
/// Returns [`None`] if there is an epoch mismatch, or the entry is empty.
|
||||
///
|
||||
/// This function is primarily intended for the `as_hal` family of functions
|
||||
/// where you may need to fallibly get a object backed by an id that could
|
||||
/// be in a different hub.
|
||||
pub(crate) fn try_get(&self, id: Id<T::Marker>) -> Result<Option<&Arc<T>>, InvalidId> {
|
||||
let (index, epoch, _) = id.unzip();
|
||||
let (result, storage_epoch) = match self.map.get(index as usize) {
|
||||
Some(&Element::Occupied(ref v, epoch)) => (Ok(Some(v)), epoch),
|
||||
Some(&Element::Vacant) => return Ok(None),
|
||||
Some(&Element::Error(epoch)) => (Err(InvalidId), epoch),
|
||||
None => return Err(InvalidId),
|
||||
};
|
||||
assert_eq!(
|
||||
epoch, storage_epoch,
|
||||
"{}[{:?}] is no longer alive",
|
||||
self.kind, id
|
||||
);
|
||||
result
|
||||
}
|
||||
|
||||
/// Get a reference to an item behind a potentially invalid ID.
|
||||
/// Panics if there is an epoch mismatch, or the entry is empty.
|
||||
pub(crate) fn get(&self, id: Id<T::Marker>) -> Result<&Arc<T>, InvalidId> {
|
||||
|
Loading…
Reference in New Issue
Block a user