fix(core): Don't use {buffer,texture}_init_actions for usage tracking

Fixes #9576
This commit is contained in:
Andy Leiserson authored and Teodor Tanasoaia committed 2026-05-25 10:48:20 +02:00
1 parent d1e15bc3d3
commit fc1aa76bad
6 files changed
+25 -19

No files matched your search

+4 -6
View File
@@ -1277,13 +1277,11 @@ impl BindGroup {
&'a self,
guard: &'a SnatchGuard,
) -> Result<&'a dyn hal::DynBindGroup, DestroyedResourceError> {
// Clippy insist on writing it this way. The idea is to return None
// if any of the raw buffer is not valid anymore.
for buffer in &self.buffer_init_actions {
buffer.buffer.try_raw(guard)?;
for buffer in self.used.buffers.used_resources() {
buffer.try_raw(guard)?;
}
for texture in &self.texture_init_actions {
texture.texture.try_raw(guard)?;
for texture in self.used.views.used_textures() {
texture.try_raw(guard)?;
}
self.raw
+5 -4
View File
@@ -728,6 +728,7 @@ impl Device {
/// implementation of a reference-counted structure).
/// The snatch lock must not be held while this function is called.
pub(crate) fn deferred_resource_destruction(&self) {
// Note that the deferred_destroy list may contain duplicate entries.
let deferred_destroy = mem::take(&mut *self.deferred_destroy.lock());
for item in deferred_destroy {
match item {
@@ -3499,12 +3500,12 @@ impl Device {
let bind_group = Arc::new(bind_group);
let weak_ref = Arc::downgrade(&bind_group);
for range in &bind_group.texture_init_actions {
let mut bind_groups = range.texture.bind_groups.lock();
for texture in bind_group.used.views.used_textures() {
let mut bind_groups = texture.bind_groups.lock();
bind_groups.push(weak_ref.clone());
}
for range in &bind_group.buffer_init_actions {
let mut bind_groups = range.buffer.bind_groups.lock();
for buffer in bind_group.used.buffers.used_resources() {
let mut bind_groups = buffer.bind_groups.lock();
bind_groups.push(weak_ref.clone());
}
+2
View File
@@ -455,6 +455,7 @@ pub struct Buffer {
pub(crate) label: String,
pub(crate) tracking_data: TrackingData,
pub(crate) map_state: Mutex<BufferMapState>,
// Bind groups that reference this buffer. May contain duplicates.
pub(crate) bind_groups: Mutex<WeakVec<BindGroup>>,
pub(crate) timestamp_normalization_bind_group: Snatchable<TimestampNormalizationBindGroup>,
pub(crate) indirect_validation_bind_groups: Snatchable<crate::indirect_validation::BindGroups>,
@@ -1366,6 +1367,7 @@ pub struct Texture {
pub(crate) tracking_data: TrackingData,
pub(crate) clear_mode: RwLock<TextureClearMode>,
pub(crate) views: Mutex<WeakVec<TextureView>>,
// Bind groups that reference this texture. May contain duplicates.
pub(crate) bind_groups: Mutex<WeakVec<BindGroup>>,
}
+3 -7
View File
@@ -57,13 +57,9 @@ impl BufferBindGroupState {
.sort_unstable_by_key(|(b, _)| b.tracker_index());
}
/// Returns a list of all buffers tracked. May contain duplicates.
pub fn used_tracker_indices(&self) -> impl Iterator<Item = TrackerIndex> + '_ {
self.buffers
.iter()
.map(|(b, _)| b.tracker_index())
.collect::<Vec<_>>()
.into_iter()
/// Returns an iterator over the tracked buffers. May contain duplicates.
pub fn used_resources(&self) -> impl Iterator<Item = &Arc<Buffer>> {
self.buffers.iter().map(|(b, _)| b)
}
/// Adds the given resource with the given state.
+5 -2
View File
@@ -106,7 +106,7 @@ use crate::{
binding_model, command,
lock::{rank, Mutex},
pipeline,
resource::{self, Labeled, RawResourceAccess, ResourceErrorIdent},
resource::{self, Labeled, RawResourceAccess, ResourceErrorIdent, Trackable},
snatch::SnatchGuard,
track::blas::BlasTracker,
};
@@ -697,7 +697,10 @@ impl Tracker {
) {
self.buffers.set_and_remove_from_usage_scope_sparse(
&mut scope.buffers,
bind_group.buffers.used_tracker_indices(),
bind_group
.buffers
.used_resources()
.map(|b| b.tracker_index()),
);
self.textures
.set_and_remove_from_usage_scope_sparse(&mut scope.textures, &bind_group.views);
+6
View File
@@ -160,6 +160,12 @@ impl TextureViewBindGroupState {
pub fn insert_single(&mut self, view: Arc<TextureView>, usage: TextureUses) {
self.views.push((view, usage));
}
/// Returns an iterator over the parent textures of the tracked views. May contain
/// duplicates.
pub fn used_textures(&self) -> impl Iterator<Item = &Arc<Texture>> {
self.views.iter().map(|(v, _)| &v.parent)
}
}
/// Container for corresponding simple and complex texture states.