From 1e784c9c0af7a785b62e3b6840ed012a7477520f Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:17:12 +0200 Subject: [PATCH] use `TrackerIndex` instead of IDs in `PendingWrites`'s fields --- wgpu-core/src/device/global.rs | 6 ++---- wgpu-core/src/device/queue.rs | 35 ++++++++++++++++++++++++++-------- wgpu-core/src/resource.rs | 12 +++++------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index 77e158790..bb3207f30 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -519,8 +519,7 @@ impl Global { .lock() .as_ref() .unwrap() - .dst_buffers - .contains_key(&buffer_id) + .contains_buffer(&buffer) { device.lock_life().future_suspected_buffers.push(buffer); } else { @@ -744,8 +743,7 @@ impl Global { .lock() .as_ref() .unwrap() - .dst_textures - .contains_key(&texture_id) + .contains_texture(&texture) { device .lock_life() diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index d22c30b71..5a890c2e0 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -20,7 +20,9 @@ use crate::{ DestroyedTexture, ParentDevice, Resource, ResourceErrorIdent, ResourceInfo, ResourceType, StagingBuffer, Texture, TextureInner, }, - resource_log, track, FastHashMap, SubmissionIndex, + resource_log, + track::{self, TrackerIndex}, + FastHashMap, SubmissionIndex, }; use hal::{CommandEncoder as _, Device as _, Queue as _}; @@ -211,9 +213,9 @@ pub(crate) struct PendingWrites { /// [`wgpu_hal::CommandEncoder`]: hal::CommandEncoder pub is_recording: bool, - pub temp_resources: Vec>, - pub dst_buffers: FastHashMap>>, - pub dst_textures: FastHashMap>>, + temp_resources: Vec>, + dst_buffers: FastHashMap>>, + dst_textures: FastHashMap>>, /// All command buffers allocated from `command_encoder`. pub executing_command_buffers: Vec, @@ -244,6 +246,25 @@ impl PendingWrites { self.temp_resources.clear(); } + pub fn insert_buffer(&mut self, buffer: &Arc>) { + self.dst_buffers + .insert(buffer.info.tracker_index(), buffer.clone()); + } + + pub fn insert_texture(&mut self, texture: &Arc>) { + self.dst_textures + .insert(texture.info.tracker_index(), texture.clone()); + } + + pub fn contains_buffer(&self, buffer: &Arc>) -> bool { + self.dst_buffers.contains_key(&buffer.info.tracker_index()) + } + + pub fn contains_texture(&self, texture: &Arc>) -> bool { + self.dst_textures + .contains_key(&texture.info.tracker_index()) + } + pub fn consume_temp(&mut self, resource: TempResource) { self.temp_resources.push(resource); } @@ -647,7 +668,7 @@ impl Global { ); } - pending_writes.dst_buffers.insert(buffer_id, dst.clone()); + pending_writes.insert_buffer(&dst); // Ensure the overwritten bytes are marked as initialized so // they don't need to be nulled prior to mapping or binding. @@ -916,9 +937,7 @@ impl Global { } pending_writes.consume(staging_buffer); - pending_writes - .dst_textures - .insert(destination.texture, dst.clone()); + pending_writes.insert_texture(&dst); Ok(()) } diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 4b9901c3a..9949ec47e 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -702,9 +702,7 @@ impl Buffer { } } pending_writes.consume_temp(queue::TempResource::Buffer(stage_buffer)); - pending_writes - .dst_buffers - .insert(self.info.id(), self.clone()); + pending_writes.insert_buffer(self); } BufferMapState::Idle => { return Err(BufferAccessError::NotMapped); @@ -775,8 +773,8 @@ impl Buffer { let mut pending_writes = device.pending_writes.lock(); let pending_writes = pending_writes.as_mut().unwrap(); - if pending_writes.dst_buffers.contains_key(&self.info.id()) { - pending_writes.temp_resources.push(temp); + if pending_writes.contains_buffer(self) { + pending_writes.consume_temp(temp); } else { let last_submit_index = self.info.submission_index(); device @@ -1167,8 +1165,8 @@ impl Texture { let mut pending_writes = device.pending_writes.lock(); let pending_writes = pending_writes.as_mut().unwrap(); - if pending_writes.dst_textures.contains_key(&self.info.id()) { - pending_writes.temp_resources.push(temp); + if pending_writes.contains_texture(self) { + pending_writes.consume_temp(temp); } else { let last_submit_index = self.info.submission_index(); device