Skip to content

Commit 43e0ebd

Browse files
committed
[wgpu-core] ray tracing: remove acceleration structures from pending writes
The acceleration structures are already being kept alive by the tracker in the command encoder.
1 parent fb9f91a commit 43e0ebd

File tree

4 files changed

+10
-70
lines changed

4 files changed

+10
-70
lines changed

wgpu-core/src/command/ray_tracing.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
device::{queue::TempResource, Device},
2+
device::queue::TempResource,
33
global::Global,
44
hub::Hub,
55
id::CommandEncoderId,
@@ -174,7 +174,6 @@ impl Global {
174174
build_command_index,
175175
&mut buf_storage,
176176
hub,
177-
device,
178177
)?;
179178

180179
let snatch_guard = device.snatchable_lock.read();
@@ -225,9 +224,6 @@ impl Global {
225224

226225
let tlas = hub.tlas_s.get(entry.tlas_id).get()?;
227226
cmd_buf_data.trackers.tlas_s.set_single(tlas.clone());
228-
if let Some(queue) = device.get_queue() {
229-
queue.pending_writes.lock().insert_tlas(&tlas);
230-
}
231227

232228
cmd_buf_data.tlas_actions.push(TlasAction {
233229
tlas: tlas.clone(),
@@ -478,7 +474,6 @@ impl Global {
478474
build_command_index,
479475
&mut buf_storage,
480476
hub,
481-
device,
482477
)?;
483478

484479
let snatch_guard = device.snatchable_lock.read();
@@ -496,9 +491,6 @@ impl Global {
496491

497492
for package in tlas_iter {
498493
let tlas = hub.tlas_s.get(package.tlas_id).get()?;
499-
if let Some(queue) = device.get_queue() {
500-
queue.pending_writes.lock().insert_tlas(&tlas);
501-
}
502494

503495
cmd_buf_data.trackers.tlas_s.set_single(tlas.clone());
504496

@@ -833,15 +825,11 @@ fn iter_blas<'a>(
833825
build_command_index: NonZeroU64,
834826
buf_storage: &mut Vec<TriangleBufferStore<'a>>,
835827
hub: &Hub,
836-
device: &Device,
837828
) -> Result<(), BuildAccelerationStructureError> {
838829
let mut temp_buffer = Vec::new();
839830
for entry in blas_iter {
840831
let blas = hub.blas_s.get(entry.blas_id).get()?;
841832
cmd_buf_data.trackers.blas_s.set_single(blas.clone());
842-
if let Some(queue) = device.get_queue() {
843-
queue.pending_writes.lock().insert_blas(&blas);
844-
}
845833

846834
cmd_buf_data.blas_actions.push(BlasAction {
847835
blas: blas.clone(),

wgpu-core/src/device/life.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ impl ActiveSubmission {
115115
if encoder.trackers.blas_s.contains(blas) {
116116
return true;
117117
}
118-
119-
if encoder.pending_blas_s.contains_key(&blas.tracker_index()) {
120-
return true;
121-
}
122118
}
123119

124120
false
@@ -134,10 +130,6 @@ impl ActiveSubmission {
134130
if encoder.trackers.tlas_s.contains(tlas) {
135131
return true;
136132
}
137-
138-
if encoder.pending_tlas_s.contains_key(&tlas.tracker_index()) {
139-
return true;
140-
}
141133
}
142134

143135
false

wgpu-core/src/device/queue.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::{
2727

2828
use smallvec::SmallVec;
2929

30-
use crate::resource::{Blas, DestroyedAccelerationStructure, Tlas};
30+
use crate::resource::DestroyedAccelerationStructure;
3131
use crate::scratch::ScratchBuffer;
3232
use std::{
3333
iter,
@@ -273,10 +273,6 @@ pub(crate) struct EncoderInFlight {
273273
pub(crate) pending_buffers: FastHashMap<TrackerIndex, Arc<Buffer>>,
274274
/// These are the textures that have been tracked by `PendingWrites`.
275275
pub(crate) pending_textures: FastHashMap<TrackerIndex, Arc<Texture>>,
276-
/// These are the BLASes that have been tracked by `PendingWrites`.
277-
pub(crate) pending_blas_s: FastHashMap<TrackerIndex, Arc<Blas>>,
278-
/// These are the TLASes that have been tracked by `PendingWrites`.
279-
pub(crate) pending_tlas_s: FastHashMap<TrackerIndex, Arc<Tlas>>,
280276
}
281277

282278
/// A private command encoder for writes made directly on the device
@@ -314,8 +310,6 @@ pub(crate) struct PendingWrites {
314310
temp_resources: Vec<TempResource>,
315311
dst_buffers: FastHashMap<TrackerIndex, Arc<Buffer>>,
316312
dst_textures: FastHashMap<TrackerIndex, Arc<Texture>>,
317-
dst_blas_s: FastHashMap<TrackerIndex, Arc<Blas>>,
318-
dst_tlas_s: FastHashMap<TrackerIndex, Arc<Tlas>>,
319313
}
320314

321315
impl PendingWrites {
@@ -326,8 +320,6 @@ impl PendingWrites {
326320
temp_resources: Vec::new(),
327321
dst_buffers: FastHashMap::default(),
328322
dst_textures: FastHashMap::default(),
329-
dst_blas_s: FastHashMap::default(),
330-
dst_tlas_s: FastHashMap::default(),
331323
}
332324
}
333325

@@ -349,22 +341,6 @@ impl PendingWrites {
349341
self.dst_textures.contains_key(&texture.tracker_index())
350342
}
351343

352-
pub fn insert_blas(&mut self, blas: &Arc<Blas>) {
353-
self.dst_blas_s.insert(blas.tracker_index(), blas.clone());
354-
}
355-
356-
pub fn insert_tlas(&mut self, tlas: &Arc<Tlas>) {
357-
self.dst_tlas_s.insert(tlas.tracker_index(), tlas.clone());
358-
}
359-
360-
pub fn contains_blas(&mut self, blas: &Arc<Blas>) -> bool {
361-
self.dst_blas_s.contains_key(&blas.tracker_index())
362-
}
363-
364-
pub fn contains_tlas(&mut self, tlas: &Arc<Tlas>) -> bool {
365-
self.dst_tlas_s.contains_key(&tlas.tracker_index())
366-
}
367-
368344
pub fn consume_temp(&mut self, resource: TempResource) {
369345
self.temp_resources.push(resource);
370346
}
@@ -383,8 +359,6 @@ impl PendingWrites {
383359
if self.is_recording {
384360
let pending_buffers = mem::take(&mut self.dst_buffers);
385361
let pending_textures = mem::take(&mut self.dst_textures);
386-
let pending_blas_s = mem::take(&mut self.dst_blas_s);
387-
let pending_tlas_s = mem::take(&mut self.dst_tlas_s);
388362

389363
let cmd_buf = unsafe { self.command_encoder.end_encoding() }
390364
.map_err(|e| device.handle_hal_error(e))?;
@@ -405,8 +379,6 @@ impl PendingWrites {
405379
trackers: Tracker::new(),
406380
pending_buffers,
407381
pending_textures,
408-
pending_blas_s,
409-
pending_tlas_s,
410382
};
411383
Ok(Some(encoder))
412384
} else {
@@ -1225,8 +1197,6 @@ impl Queue {
12251197
trackers: baked.trackers,
12261198
pending_buffers: FastHashMap::default(),
12271199
pending_textures: FastHashMap::default(),
1228-
pending_blas_s: FastHashMap::default(),
1229-
pending_tlas_s: FastHashMap::default(),
12301200
});
12311201
}
12321202

wgpu-core/src/resource.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,15 +1959,10 @@ impl Blas {
19591959
};
19601960

19611961
if let Some(queue) = device.get_queue() {
1962-
let mut pending_writes = queue.pending_writes.lock();
1963-
if pending_writes.contains_blas(self) {
1964-
pending_writes.consume_temp(temp);
1965-
} else {
1966-
let mut life_lock = queue.lock_life();
1967-
let last_submit_index = life_lock.get_blas_latest_submission_index(self);
1968-
if let Some(last_submit_index) = last_submit_index {
1969-
life_lock.schedule_resource_destruction(temp, last_submit_index);
1970-
}
1962+
let mut life_lock = queue.lock_life();
1963+
let last_submit_index = life_lock.get_blas_latest_submission_index(self);
1964+
if let Some(last_submit_index) = last_submit_index {
1965+
life_lock.schedule_resource_destruction(temp, last_submit_index);
19711966
}
19721967
}
19731968

@@ -2054,15 +2049,10 @@ impl Tlas {
20542049
};
20552050

20562051
if let Some(queue) = device.get_queue() {
2057-
let mut pending_writes = queue.pending_writes.lock();
2058-
if pending_writes.contains_tlas(self) {
2059-
pending_writes.consume_temp(temp);
2060-
} else {
2061-
let mut life_lock = queue.lock_life();
2062-
let last_submit_index = life_lock.get_tlas_latest_submission_index(self);
2063-
if let Some(last_submit_index) = last_submit_index {
2064-
life_lock.schedule_resource_destruction(temp, last_submit_index);
2065-
}
2052+
let mut life_lock = queue.lock_life();
2053+
let last_submit_index = life_lock.get_tlas_latest_submission_index(self);
2054+
if let Some(last_submit_index) = last_submit_index {
2055+
life_lock.schedule_resource_destruction(temp, last_submit_index);
20662056
}
20672057
}
20682058

0 commit comments

Comments
 (0)