Skip to content

Commit

Permalink
use TrackerIndex instead of IDs in PendingWrites's fields
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Jun 20, 2024
1 parent 2e1e1cd commit 1e784c9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
6 changes: 2 additions & 4 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -744,8 +743,7 @@ impl Global {
.lock()
.as_ref()
.unwrap()
.dst_textures
.contains_key(&texture_id)
.contains_texture(&texture)
{
device
.lock_life()
Expand Down
35 changes: 27 additions & 8 deletions wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _};
Expand Down Expand Up @@ -211,9 +213,9 @@ pub(crate) struct PendingWrites<A: HalApi> {
/// [`wgpu_hal::CommandEncoder`]: hal::CommandEncoder
pub is_recording: bool,

pub temp_resources: Vec<TempResource<A>>,
pub dst_buffers: FastHashMap<id::BufferId, Arc<Buffer<A>>>,
pub dst_textures: FastHashMap<id::TextureId, Arc<Texture<A>>>,
temp_resources: Vec<TempResource<A>>,
dst_buffers: FastHashMap<TrackerIndex, Arc<Buffer<A>>>,
dst_textures: FastHashMap<TrackerIndex, Arc<Texture<A>>>,

/// All command buffers allocated from `command_encoder`.
pub executing_command_buffers: Vec<A::CommandBuffer>,
Expand Down Expand Up @@ -244,6 +246,25 @@ impl<A: HalApi> PendingWrites<A> {
self.temp_resources.clear();
}

pub fn insert_buffer(&mut self, buffer: &Arc<Buffer<A>>) {
self.dst_buffers
.insert(buffer.info.tracker_index(), buffer.clone());
}

pub fn insert_texture(&mut self, texture: &Arc<Texture<A>>) {
self.dst_textures
.insert(texture.info.tracker_index(), texture.clone());
}

pub fn contains_buffer(&self, buffer: &Arc<Buffer<A>>) -> bool {
self.dst_buffers.contains_key(&buffer.info.tracker_index())
}

pub fn contains_texture(&self, texture: &Arc<Texture<A>>) -> bool {
self.dst_textures
.contains_key(&texture.info.tracker_index())
}

pub fn consume_temp(&mut self, resource: TempResource<A>) {
self.temp_resources.push(resource);
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(())
}
Expand Down
12 changes: 5 additions & 7 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,7 @@ impl<A: HalApi> Buffer<A> {
}
}
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);
Expand Down Expand Up @@ -775,8 +773,8 @@ impl<A: HalApi> Buffer<A> {

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
Expand Down Expand Up @@ -1167,8 +1165,8 @@ impl<A: HalApi> Texture<A> {

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
Expand Down

0 comments on commit 1e784c9

Please sign in to comment.