mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-29 01:23:57 +01:00
Merge #714
714: Track buffers and textures in the future submissions r=cwfitzgerald a=kvark **Connections** Fixes https://github.com/gfx-rs/wgpu-rs/issues/362 **Description** When we do `write_buffer` or have it mapped on creation, we record the copy command in a "pending command buffer", which is only actually executed on the next submission. We adjust the submission index on the buffer accordingly. If the buffer is dropped *before* the next submission, and there happens to be a `maintain()` step, there is code that checks if the buffer-associated submission is one of the currently executing ones. If it doesn't fine an active one, it considers the last-used submission to already be done with, which is precisely what is not happening here, since the submission hasn't been scheduled yet. The solution here is to always defer suspecting buffers and textures for deletion till the next submission. The buffers and textures are the only objects that may have "future" submission index, due to `write_buffer` and `write_texture`. **Testing** Confirmed on Linux. Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
commit
b0b99d89b7
2 files changed
+15
-4
No files matched your search
@@ -198,6 +198,11 @@ struct ActiveSubmission<B: hal::Backend> {
|
||||
pub struct LifetimeTracker<B: hal::Backend> {
|
||||
/// Resources that the user has requested be mapped, but are still in use.
|
||||
mapped: Vec<Stored<id::BufferId>>,
|
||||
/// Buffers can be used in a submission that is yet to be made, by the
|
||||
/// means of `write_buffer()`, so we have a special place for them.
|
||||
pub future_suspected_buffers: Vec<id::BufferId>,
|
||||
/// Textures can be used in the upcoming submission by `write_texture`.
|
||||
pub future_suspected_textures: Vec<id::TextureId>,
|
||||
/// Resources that are suspected for destruction.
|
||||
pub suspected_resources: SuspectedResources,
|
||||
/// Resources that are not referenced any more but still used by GPU.
|
||||
@@ -214,6 +219,8 @@ impl<B: hal::Backend> LifetimeTracker<B> {
|
||||
pub fn new() -> Self {
|
||||
LifetimeTracker {
|
||||
mapped: Vec::new(),
|
||||
future_suspected_buffers: Vec::new(),
|
||||
future_suspected_textures: Vec::new(),
|
||||
suspected_resources: SuspectedResources::default(),
|
||||
active: Vec::new(),
|
||||
free_resources: NonReferencedResources::new(),
|
||||
@@ -230,6 +237,12 @@ impl<B: hal::Backend> LifetimeTracker<B> {
|
||||
) {
|
||||
let mut last_resources = NonReferencedResources::new();
|
||||
last_resources.buffers.extend(temp_buffers);
|
||||
self.suspected_resources
|
||||
.buffers
|
||||
.extend(self.future_suspected_buffers.drain(..));
|
||||
self.suspected_resources
|
||||
.textures
|
||||
.extend(self.future_suspected_textures.drain(..));
|
||||
self.suspected_resources.extend(new_suspects);
|
||||
self.active.alloc().init(ActiveSubmission {
|
||||
index,
|
||||
|
||||
@@ -879,8 +879,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let (device_guard, mut token) = hub.devices.read(&mut token);
|
||||
device_guard[device_id]
|
||||
.lock_life(&mut token)
|
||||
.suspected_resources
|
||||
.buffers
|
||||
.future_suspected_buffers
|
||||
.push(buffer_id);
|
||||
}
|
||||
|
||||
@@ -932,8 +931,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let (device_guard, mut token) = hub.devices.read(&mut token);
|
||||
device_guard[device_id]
|
||||
.lock_life(&mut token)
|
||||
.suspected_resources
|
||||
.textures
|
||||
.future_suspected_textures
|
||||
.push(texture_id);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user