mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Track resources used in commands by the device
This commit is contained in:
parent
d597e97db8
commit
a04df23a10
@ -512,16 +512,26 @@ pub extern "C" fn wgpu_queue_submit(
|
||||
slice::from_raw_parts(command_buffer_ptr, command_buffer_count)
|
||||
};
|
||||
|
||||
let mut buffer_guard = HUB.buffers.lock();
|
||||
let mut texture_guard = HUB.textures.lock();
|
||||
let old_submit_index = device.life_guard.submission_index.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
//TODO: if multiple command buffers are submitted, we can re-use the last
|
||||
// native command buffer of the previous chain instead of always creating
|
||||
// a temporary one, since the chains are not finished.
|
||||
|
||||
//TODO: add used resources to the active frame
|
||||
let mut resources = Vec::new();
|
||||
|
||||
// finish all the command buffers first
|
||||
for &cmb_id in command_buffer_ids {
|
||||
let comb = command_buffer_guard.get_mut(cmb_id);
|
||||
// update submission IDs
|
||||
for id in comb.buffer_tracker.used() {
|
||||
buffer_guard.get(id).life_guard.submission_index.store(old_submit_index, Ordering::Release);
|
||||
}
|
||||
for id in comb.texture_tracker.used() {
|
||||
texture_guard.get(id).life_guard.submission_index.store(old_submit_index, Ordering::Release);
|
||||
}
|
||||
|
||||
// execute resource transitions
|
||||
let mut transit = device.com_allocator.extend(comb);
|
||||
transit.begin(
|
||||
hal::command::CommandBufferFlags::ONE_TIME_SUBMIT,
|
||||
@ -560,19 +570,14 @@ pub extern "C" fn wgpu_queue_submit(
|
||||
}
|
||||
}
|
||||
|
||||
let old_submit_index = device.life_guard.submission_index.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
if let Ok(mut destroyed) = device.destroyed.lock() {
|
||||
let mut buffer_guard = HUB.buffers.lock();
|
||||
let mut texture_guard = HUB.textures.lock();
|
||||
|
||||
destroyed.triage_referenced(&mut buffer_guard, &mut texture_guard);
|
||||
destroyed.cleanup(&device.raw);
|
||||
|
||||
destroyed.active.push(ActiveFrame {
|
||||
submission_index: old_submit_index + 1,
|
||||
fence,
|
||||
resources,
|
||||
resources: Vec::new(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -70,6 +70,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the last usage on a resource.
|
||||
pub(crate) fn query(
|
||||
&mut self, stored: &Stored<I>, default: U
|
||||
) -> Query<U> {
|
||||
@ -94,6 +95,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
/// Transit a specified resource into a different usage.
|
||||
pub(crate) fn transit(
|
||||
&mut self, id: I, ref_count: &RefCount, usage: U, permit: TrackPermit
|
||||
) -> Result<Tracktion<U>, U> {
|
||||
@ -123,6 +125,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
/// Consume another tacker, adding it's transitions to `self`.
|
||||
pub fn consume<'a>(
|
||||
&'a mut self, other: &'a Self
|
||||
) -> impl 'a + Iterator<Item = (I, Range<U>)> {
|
||||
@ -143,4 +146,9 @@ impl<
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Return an iterator over used resources keys.
|
||||
pub fn used<'a>(&'a self) -> impl 'a + Iterator<Item = I> {
|
||||
self.map.keys().map(|&WeaklyStored(ref id)| id.clone())
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user