Fix lock token lifetimes

This commit is contained in:
Dzmitry Malyshau 2019-12-08 17:00:30 -05:00
parent 501f9da804
commit bd24c20d4c
4 changed files with 26 additions and 18 deletions

View File

@ -161,8 +161,9 @@ impl<F> Global<F> {
) {
let hub = B::hub(self);
let mut token = Token::root();
let (mut pass_guard, mut token) = hub.compute_passes.write(&mut token);
let (buffer_guard, _) = hub.buffers.read(&mut token);
let (mut pass_guard, _) = hub.compute_passes.write(&mut token);
let pass = &mut pass_guard[pass_id];
let (src_buffer, src_pending) = pass.trackers.buffers.use_replace(

View File

@ -383,7 +383,7 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
) {
let hub = B::hub(self);
let mut token = Token::root();
let (mut pass_guard, _) = hub.render_passes.write(&mut token);
let (mut pass_guard, mut token) = hub.render_passes.write(&mut token);
let (buffer_guard, _) = hub.buffers.read(&mut token);
let pass = &mut pass_guard[pass_id];
pass.is_ready().unwrap();
@ -447,7 +447,7 @@ impl<F: IdentityFilter<RenderPassId>> Global<F> {
) {
let hub = B::hub(self);
let mut token = Token::root();
let (mut pass_guard, _) = hub.render_passes.write(&mut token);
let (mut pass_guard, mut token) = hub.render_passes.write(&mut token);
let (buffer_guard, _) = hub.buffers.read(&mut token);
let pass = &mut pass_guard[pass_id];
pass.is_ready().unwrap();

View File

@ -811,7 +811,7 @@ impl<F: IdentityFilter<BufferId>> Global<F> {
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, _) = hub.devices.read(&mut token);
let (device_guard, mut token) = hub.devices.read(&mut token);
let device = &device_guard[device_id];
let buffer = device.create_buffer(device_id, desc);
let ref_count = buffer.life_guard.ref_count.clone();
@ -839,7 +839,7 @@ impl<F: IdentityFilter<BufferId>> Global<F> {
let mut desc = desc.clone();
desc.usage |= resource::BufferUsage::MAP_WRITE;
let (device_guard, _) = hub.devices.read(&mut token);
let (device_guard, mut token) = hub.devices.read(&mut token);
let device = &device_guard[device_id];
let mut buffer = device.create_buffer(device_id, &desc);
let ref_count = buffer.life_guard.ref_count.clone();
@ -960,7 +960,7 @@ impl<F: IdentityFilter<TextureId>> Global<F> {
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, _) = hub.devices.read(&mut token);
let (device_guard, mut token) = hub.devices.read(&mut token);
let device = &device_guard[device_id];
let texture = device.create_texture(device_id, desc);
let range = texture.full_range.clone();
@ -1267,7 +1267,7 @@ impl<F: IdentityFilter<BindGroupId>> Global<F> {
let (device_guard, mut token) = hub.devices.read(&mut token);
let device = &device_guard[device_id];
let (bind_group_layout_guard, _) = hub.bind_group_layouts.read(&mut token);
let (bind_group_layout_guard, mut token) = hub.bind_group_layouts.read(&mut token);
let bind_group_layout = &bind_group_layout_guard[desc.layout];
let bindings =
unsafe { slice::from_raw_parts(desc.bindings, desc.bindings_length as usize) };
@ -2074,8 +2074,9 @@ impl<F: IdentityFilter<SwapChainId>> Global<F> {
impl<F: AllIdentityFilter> Global<F> {
pub fn device_poll<B: GfxBackend>(&self, device_id: DeviceId, force_wait: bool) {
let hub = B::hub(self);
let mut token = Token::root();
let callbacks = {
let (device_guard, mut token) = hub.devices.read(&mut Token::root());
let (device_guard, mut token) = hub.devices.read(&mut token);
device_guard[device_id].maintain(self, force_wait, &mut token)
};
Device::<B>::fire_map_callbacks(callbacks);
@ -2085,7 +2086,8 @@ impl<F: AllIdentityFilter> Global<F> {
impl<F: AllIdentityFilter + IdentityFilter<DeviceId>> Global<F> {
pub fn device_destroy<B: GfxBackend>(&self, device_id: DeviceId) {
let hub = B::hub(self);
let (device, mut token) = hub.devices.unregister(device_id, &mut Token::root());
let mut token = Token::root();
let (device, mut token) = hub.devices.unregister(device_id, &mut token);
device.maintain(self, true, &mut token);
device.com_allocator.destroy(&device.raw);
}

View File

@ -167,6 +167,7 @@ impl<B: hal::Backend> Access<BindGroupLayout<B>> for Root {}
impl<B: hal::Backend> Access<BindGroupLayout<B>> for Device<B> {}
impl<B: hal::Backend> Access<BindGroup<B>> for Root {}
impl<B: hal::Backend> Access<BindGroup<B>> for Device<B> {}
impl<B: hal::Backend> Access<BindGroup<B>> for BindGroupLayout<B> {}
impl<B: hal::Backend> Access<BindGroup<B>> for PipelineLayout<B> {}
impl<B: hal::Backend> Access<BindGroup<B>> for CommandBuffer<B> {}
impl<B: hal::Backend> Access<CommandBuffer<B>> for Root {}
@ -319,17 +320,17 @@ impl<T, I: TypedId + Copy, F> Registry<T, I, F> {
assert!(old.is_none());
}
pub fn read<A: Access<T>>(
&self,
_token: &mut Token<A>,
) -> (RwLockReadGuard<Storage<T, I>>, Token<T>) {
pub fn read<'a, A: Access<T>>(
&'a self,
_token: &'a mut Token<A>,
) -> (RwLockReadGuard<'a, Storage<T, I>>, Token<'a, T>) {
(self.data.read(), Token::new())
}
pub fn write<A: Access<T>>(
&self,
_token: &mut Token<A>,
) -> (RwLockWriteGuard<Storage<T, I>>, Token<T>) {
pub fn write<'a, A: Access<T>>(
&'a self,
_token: &'a mut Token<A>,
) -> (RwLockWriteGuard<'a, Storage<T, I>>, Token<'a, T>) {
(self.data.write(), Token::new())
}
}
@ -346,7 +347,11 @@ impl<T, I: TypedId + Copy, F: IdentityFilter<I>> Registry<T, I, F> {
id
}
pub fn unregister<A: Access<T>>(&self, id: I, _token: &mut Token<A>) -> (T, Token<T>) {
pub fn unregister<'a, A: Access<T>>(
&self,
id: I,
_token: &'a mut Token<A>,
) -> (T, Token<'a, T>) {
let value = self.data.write().remove(id).unwrap();
//Note: careful about the order here!
self.identity.free(id);