use TrackerIndex instead of IDs in PendingWrites's fields

This commit is contained in:
teoxoy 2024-06-20 14:17:12 +02:00 committed by Teodor Tanasoaia
parent 2e1e1cd26e
commit 1e784c9c0a
3 changed files with 34 additions and 19 deletions

View File

@ -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()

View File

@ -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<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>,
@ -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);
}
@ -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(())
}

View File

@ -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);
@ -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
@ -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