diff --git a/player/src/lib.rs b/player/src/lib.rs index f042ed6dd8..6aca3382f1 100644 --- a/player/src/lib.rs +++ b/player/src/lib.rs @@ -451,18 +451,12 @@ impl GlobalPlay for wgc::global::Global { Action::CreateBlas { id, desc, sizes } => { self.device_create_blas(device, &desc, sizes, Some(id)); } - Action::FreeBlas(id) => { - self.blas_destroy(id).unwrap(); - } Action::DestroyBlas(id) => { self.blas_drop(id); } Action::CreateTlas { id, desc } => { self.device_create_tlas(device, &desc, Some(id)); } - Action::FreeTlas(id) => { - self.tlas_destroy(id).unwrap(); - } Action::DestroyTlas(id) => { self.tlas_drop(id); } diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 88cf874d3a..f4ff30a392 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -28,6 +28,7 @@ pub use timestamp_writes::PassTimestampWrites; use self::memory_init::CommandBufferTextureMemoryActions; +use crate::device::queue::TempResource; use crate::device::{Device, DeviceError, MissingFeatures}; use crate::lock::{rank, Mutex}; use crate::snatch::SnatchGuard; @@ -432,6 +433,7 @@ impl Drop for CommandEncoder { pub(crate) struct BakedCommands { pub(crate) encoder: CommandEncoder, pub(crate) trackers: Tracker, + pub(crate) temp_resources: Vec, buffer_memory_init_actions: Vec, texture_memory_actions: CommandBufferTextureMemoryActions, } @@ -460,6 +462,7 @@ pub struct CommandBufferMutable { blas_actions: Vec, tlas_actions: Vec, + temp_resources: Vec, #[cfg(feature = "trace")] pub(crate) commands: Option>, @@ -479,6 +482,7 @@ impl CommandBufferMutable { BakedCommands { encoder: self.encoder, trackers: self.trackers, + temp_resources: self.temp_resources, buffer_memory_init_actions: self.buffer_memory_init_actions, texture_memory_actions: self.texture_memory_actions, } @@ -545,6 +549,7 @@ impl CommandBuffer { pending_query_resets: QueryResetMap::new(), blas_actions: Default::default(), tlas_actions: Default::default(), + temp_resources: Default::default(), #[cfg(feature = "trace")] commands: if device.trace.lock().is_some() { Some(Vec::new()) diff --git a/wgpu-core/src/command/ray_tracing.rs b/wgpu-core/src/command/ray_tracing.rs index 9395c20fc1..2be33d0950 100644 --- a/wgpu-core/src/command/ray_tracing.rs +++ b/wgpu-core/src/command/ray_tracing.rs @@ -1,5 +1,5 @@ use crate::{ - device::{queue::TempResource, Device}, + device::queue::TempResource, global::Global, hub::Hub, id::CommandEncoderId, @@ -81,12 +81,7 @@ impl Global { let device = &cmd_buf.device; - if !device - .features - .contains(Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE) - { - return Err(BuildAccelerationStructureError::MissingFeature); - } + device.require_features(Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE)?; let build_command_index = NonZeroU64::new( device @@ -179,7 +174,6 @@ impl Global { build_command_index, &mut buf_storage, hub, - device, )?; let snatch_guard = device.snatchable_lock.read(); @@ -199,18 +193,13 @@ impl Global { let mut tlas_buf_storage = Vec::new(); for entry in tlas_iter { - let instance_buffer = match hub.buffers.get(entry.instance_buffer_id).get() { - Ok(buffer) => buffer, - Err(_) => { - return Err(BuildAccelerationStructureError::InvalidBufferId); - } - }; + let instance_buffer = hub.buffers.get(entry.instance_buffer_id).get()?; let data = cmd_buf_data.trackers.buffers.set_single( &instance_buffer, BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, ); tlas_buf_storage.push(TlasBufferStore { - buffer: instance_buffer.clone(), + buffer: instance_buffer, transition: data, entry: entry.clone(), }); @@ -221,14 +210,9 @@ impl Global { let instance_buffer = { let (instance_buffer, instance_pending) = (&mut tlas_buf.buffer, &mut tlas_buf.transition); - let instance_raw = instance_buffer.raw.get(&snatch_guard).ok_or( - BuildAccelerationStructureError::InvalidBuffer(instance_buffer.error_ident()), - )?; - if !instance_buffer.usage.contains(BufferUsages::TLAS_INPUT) { - return Err(BuildAccelerationStructureError::MissingTlasInputUsageFlag( - instance_buffer.error_ident(), - )); - } + let instance_raw = instance_buffer.try_raw(&snatch_guard)?; + instance_buffer.check_usage(BufferUsages::TLAS_INPUT)?; + if let Some(barrier) = instance_pending .take() .map(|pending| pending.into_hal(instance_buffer, &snatch_guard)) @@ -238,15 +222,8 @@ impl Global { instance_raw }; - let tlas = hub - .tlas_s - .get(entry.tlas_id) - .get() - .map_err(|_| BuildAccelerationStructureError::InvalidTlasId)?; - cmd_buf_data.trackers.tlas_s.set_single(tlas.clone()); - if let Some(queue) = device.get_queue() { - queue.pending_writes.lock().insert_tlas(&tlas); - } + let tlas = hub.tlas_s.get(entry.tlas_id).get()?; + cmd_buf_data.trackers.tlas_s.insert_single(tlas.clone()); cmd_buf_data.tlas_actions.push(TlasAction { tlas: tlas.clone(), @@ -266,7 +243,7 @@ impl Global { tlas, entries: hal::AccelerationStructureEntries::Instances( hal::AccelerationStructureInstances { - buffer: Some(instance_buffer.as_ref()), + buffer: Some(instance_buffer), offset: 0, count: entry.instance_count, }, @@ -311,9 +288,7 @@ impl Global { mode: hal::AccelerationStructureBuildMode::Build, flags: tlas.flags, source_acceleration_structure: None, - destination_acceleration_structure: tlas.raw(&snatch_guard).ok_or( - BuildAccelerationStructureError::InvalidTlas(tlas.error_ident()), - )?, + destination_acceleration_structure: tlas.try_raw(&snatch_guard)?, scratch_buffer: scratch_buffer.raw(), scratch_buffer_offset: *scratch_buffer_offset, }) @@ -354,12 +329,9 @@ impl Global { } } - if let Some(queue) = device.get_queue() { - queue - .pending_writes - .lock() - .consume_temp(TempResource::ScratchBuffer(scratch_buffer)); - } + cmd_buf_data + .temp_resources + .push(TempResource::ScratchBuffer(scratch_buffer)); cmd_buf_data_guard.mark_successful(); Ok(()) @@ -381,12 +353,7 @@ impl Global { let device = &cmd_buf.device; - if !device - .features - .contains(Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE) - { - return Err(BuildAccelerationStructureError::MissingFeature); - } + device.require_features(Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE)?; let build_command_index = NonZeroU64::new( device @@ -504,7 +471,6 @@ impl Global { build_command_index, &mut buf_storage, hub, - device, )?; let snatch_guard = device.snatchable_lock.read(); @@ -521,17 +487,11 @@ impl Global { let mut tlas_lock_store = Vec::<(Option, Arc)>::new(); for package in tlas_iter { - let tlas = hub - .tlas_s - .get(package.tlas_id) - .get() - .map_err(|_| BuildAccelerationStructureError::InvalidTlasId)?; - if let Some(queue) = device.get_queue() { - queue.pending_writes.lock().insert_tlas(&tlas); - } - cmd_buf_data.trackers.tlas_s.set_single(tlas.clone()); + let tlas = hub.tlas_s.get(package.tlas_id).get()?; - tlas_lock_store.push((Some(package), tlas.clone())) + cmd_buf_data.trackers.tlas_s.insert_single(tlas.clone()); + + tlas_lock_store.push((Some(package), tlas)) } let mut scratch_buffer_tlas_size = 0; @@ -558,14 +518,9 @@ impl Global { tlas.error_ident(), )); } - let blas = hub - .blas_s - .get(instance.blas_id) - .get() - .map_err(|_| BuildAccelerationStructureError::InvalidBlasIdForInstance)? - .clone(); + let blas = hub.blas_s.get(instance.blas_id).get()?; - cmd_buf_data.trackers.blas_s.set_single(blas.clone()); + cmd_buf_data.trackers.blas_s.insert_single(blas.clone()); instance_buffer_staging_source.extend(device.raw().tlas_instance_to_bytes( hal::TlasInstance { @@ -581,7 +536,7 @@ impl Global { dependencies.push(blas.clone()); cmd_buf_data.blas_actions.push(BlasAction { - blas: blas.clone(), + blas, kind: crate::ray_tracing::BlasActionKind::Use, }); } @@ -659,13 +614,7 @@ impl Global { mode: hal::AccelerationStructureBuildMode::Build, flags: tlas.flags, source_acceleration_structure: None, - destination_acceleration_structure: tlas - .raw - .get(&snatch_guard) - .ok_or(BuildAccelerationStructureError::InvalidTlas( - tlas.error_ident(), - ))? - .as_ref(), + destination_acceleration_structure: tlas.try_raw(&snatch_guard)?, scratch_buffer: scratch_buffer.raw(), scratch_buffer_offset: *scratch_buffer_offset, }) @@ -773,21 +722,15 @@ impl Global { } if let Some(staging_buffer) = staging_buffer { - if let Some(queue) = device.get_queue() { - queue - .pending_writes - .lock() - .consume_temp(TempResource::StagingBuffer(staging_buffer)); - } + cmd_buf_data + .temp_resources + .push(TempResource::StagingBuffer(staging_buffer)); } } - if let Some(queue) = device.get_queue() { - queue - .pending_writes - .lock() - .consume_temp(TempResource::ScratchBuffer(scratch_buffer)); - } + cmd_buf_data + .temp_resources + .push(TempResource::ScratchBuffer(scratch_buffer)); cmd_buf_data_guard.mark_successful(); Ok(()) @@ -857,9 +800,7 @@ impl CommandBufferMutable { action.tlas.error_ident(), )); } - if blas.raw.get(snatch_guard).is_none() { - return Err(ValidateTlasActionsError::InvalidBlas(blas.error_ident())); - } + blas.try_raw(snatch_guard)?; } } } @@ -875,19 +816,11 @@ fn iter_blas<'a>( build_command_index: NonZeroU64, buf_storage: &mut Vec>, hub: &Hub, - device: &Device, ) -> Result<(), BuildAccelerationStructureError> { let mut temp_buffer = Vec::new(); for entry in blas_iter { - let blas = hub - .blas_s - .get(entry.blas_id) - .get() - .map_err(|_| BuildAccelerationStructureError::InvalidBlasId)?; - cmd_buf_data.trackers.blas_s.set_single(blas.clone()); - if let Some(queue) = device.get_queue() { - queue.pending_writes.lock().insert_blas(&blas); - } + let blas = hub.blas_s.get(entry.blas_id).get()?; + cmd_buf_data.trackers.blas_s.insert_single(blas.clone()); cmd_buf_data.blas_actions.push(BlasAction { blas: blas.clone(), @@ -966,19 +899,13 @@ fn iter_blas<'a>( blas.error_ident(), )); } - let vertex_buffer = match hub.buffers.get(mesh.vertex_buffer).get() { - Ok(buffer) => buffer, - Err(_) => return Err(BuildAccelerationStructureError::InvalidBufferId), - }; + let vertex_buffer = hub.buffers.get(mesh.vertex_buffer).get()?; let vertex_pending = cmd_buf_data.trackers.buffers.set_single( &vertex_buffer, BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, ); let index_data = if let Some(index_id) = mesh.index_buffer { - let index_buffer = match hub.buffers.get(index_id).get() { - Ok(buffer) => buffer, - Err(_) => return Err(BuildAccelerationStructureError::InvalidBufferId), - }; + let index_buffer = hub.buffers.get(index_id).get()?; if mesh.index_buffer_offset.is_none() || mesh.size.index_count.is_none() || mesh.size.index_count.is_none() @@ -991,15 +918,12 @@ fn iter_blas<'a>( &index_buffer, BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, ); - Some((index_buffer.clone(), data)) + Some((index_buffer, data)) } else { None }; let transform_data = if let Some(transform_id) = mesh.transform_buffer { - let transform_buffer = match hub.buffers.get(transform_id).get() { - Ok(buffer) => buffer, - Err(_) => return Err(BuildAccelerationStructureError::InvalidBufferId), - }; + let transform_buffer = hub.buffers.get(transform_id).get()?; if mesh.transform_buffer_offset.is_none() { return Err(BuildAccelerationStructureError::MissingAssociatedData( transform_buffer.error_ident(), @@ -1014,7 +938,7 @@ fn iter_blas<'a>( None }; temp_buffer.push(TriangleBufferStore { - vertex_buffer: vertex_buffer.clone(), + vertex_buffer, vertex_transition: vertex_pending, index_buffer_transition: index_data, transform_buffer_transition: transform_data, @@ -1024,7 +948,7 @@ fn iter_blas<'a>( } if let Some(last) = temp_buffer.last_mut() { - last.ending_blas = Some(blas.clone()); + last.ending_blas = Some(blas); buf_storage.append(&mut temp_buffer); } } @@ -1050,14 +974,9 @@ fn iter_buffers<'a, 'b>( let mesh = &buf.geometry; let vertex_buffer = { let vertex_buffer = buf.vertex_buffer.as_ref(); - let vertex_raw = vertex_buffer.raw.get(snatch_guard).ok_or( - BuildAccelerationStructureError::InvalidBuffer(vertex_buffer.error_ident()), - )?; - if !vertex_buffer.usage.contains(BufferUsages::BLAS_INPUT) { - return Err(BuildAccelerationStructureError::MissingBlasInputUsageFlag( - vertex_buffer.error_ident(), - )); - } + let vertex_raw = vertex_buffer.try_raw(snatch_guard)?; + vertex_buffer.check_usage(BufferUsages::BLAS_INPUT)?; + if let Some(barrier) = buf .vertex_transition .take() @@ -1077,10 +996,7 @@ fn iter_buffers<'a, 'b>( let vertex_buffer_offset = mesh.first_vertex as u64 * mesh.vertex_stride; cmd_buf_data.buffer_memory_init_actions.extend( vertex_buffer.initialization_status.read().create_action( - &hub.buffers - .get(mesh.vertex_buffer) - .get() - .map_err(|_| BuildAccelerationStructureError::InvalidBufferId)?, + &hub.buffers.get(mesh.vertex_buffer).get()?, vertex_buffer_offset ..(vertex_buffer_offset + mesh.size.vertex_count as u64 * mesh.vertex_stride), @@ -1092,14 +1008,9 @@ fn iter_buffers<'a, 'b>( let index_buffer = if let Some((ref mut index_buffer, ref mut index_pending)) = buf.index_buffer_transition { - let index_raw = index_buffer.raw.get(snatch_guard).ok_or( - BuildAccelerationStructureError::InvalidBuffer(index_buffer.error_ident()), - )?; - if !index_buffer.usage.contains(BufferUsages::BLAS_INPUT) { - return Err(BuildAccelerationStructureError::MissingBlasInputUsageFlag( - index_buffer.error_ident(), - )); - } + let index_raw = index_buffer.try_raw(snatch_guard)?; + index_buffer.check_usage(BufferUsages::BLAS_INPUT)?; + if let Some(barrier) = index_pending .take() .map(|pending| pending.into_hal(index_buffer, snatch_guard)) @@ -1155,14 +1066,9 @@ fn iter_buffers<'a, 'b>( transform_buffer.error_ident(), )); } - let transform_raw = transform_buffer.raw.get(snatch_guard).ok_or( - BuildAccelerationStructureError::InvalidBuffer(transform_buffer.error_ident()), - )?; - if !transform_buffer.usage.contains(BufferUsages::BLAS_INPUT) { - return Err(BuildAccelerationStructureError::MissingBlasInputUsageFlag( - transform_buffer.error_ident(), - )); - } + let transform_raw = transform_buffer.try_raw(snatch_guard)?; + transform_buffer.check_usage(BufferUsages::BLAS_INPUT)?; + if let Some(barrier) = transform_pending .take() .map(|pending| pending.into_hal(transform_buffer, snatch_guard)) @@ -1199,7 +1105,7 @@ fn iter_buffers<'a, 'b>( }; let triangles = hal::AccelerationStructureTriangles { - vertex_buffer: Some(vertex_buffer.as_ref()), + vertex_buffer: Some(vertex_buffer), vertex_format: mesh.size.vertex_format, first_vertex: mesh.first_vertex, vertex_count: mesh.size.vertex_count, @@ -1208,13 +1114,13 @@ fn iter_buffers<'a, 'b>( dyn hal::DynBuffer, > { format: mesh.size.index_format.unwrap(), - buffer: Some(index_buffer.as_ref()), + buffer: Some(index_buffer), offset: mesh.index_buffer_offset.unwrap() as u32, count: mesh.size.index_count.unwrap(), }), transform: transform_buffer.map(|transform_buffer| { hal::AccelerationStructureTriangleTransform { - buffer: transform_buffer.as_ref(), + buffer: transform_buffer, offset: mesh.transform_buffer_offset.unwrap() as u32, } }), @@ -1264,13 +1170,7 @@ fn map_blas<'a>( mode: hal::AccelerationStructureBuildMode::Build, flags: blas.flags, source_acceleration_structure: None, - destination_acceleration_structure: blas - .raw - .get(snatch_guard) - .ok_or(BuildAccelerationStructureError::InvalidBlas( - blas.error_ident(), - ))? - .as_ref(), + destination_acceleration_structure: blas.try_raw(snatch_guard)?, scratch_buffer, scratch_buffer_offset: *scratch_buffer_offset, }) diff --git a/wgpu-core/src/device/life.rs b/wgpu-core/src/device/life.rs index 83fe377d81..4d91d1d98f 100644 --- a/wgpu-core/src/device/life.rs +++ b/wgpu-core/src/device/life.rs @@ -9,7 +9,6 @@ use crate::{ }; use smallvec::SmallVec; -use crate::resource::{Blas, Tlas}; use std::sync::Arc; use thiserror::Error; @@ -29,9 +28,6 @@ struct ActiveSubmission { /// submission has completed. index: SubmissionIndex, - /// Temporary resources to be freed once this queue submission has completed. - temp_resources: Vec, - /// Buffers to be mapped once this submission has completed. mapped: Vec>, @@ -104,44 +100,6 @@ impl ActiveSubmission { false } - - pub fn contains_blas(&self, blas: &Blas) -> bool { - for encoder in &self.encoders { - // The ownership location of blas's depends on where the command encoder - // came from. If it is the staging command encoder on the queue, it is - // in the pending buffer list. If it came from a user command encoder, - // it is in the tracker. - - if encoder.trackers.blas_s.contains(blas) { - return true; - } - - if encoder.pending_blas_s.contains_key(&blas.tracker_index()) { - return true; - } - } - - false - } - - pub fn contains_tlas(&self, tlas: &Tlas) -> bool { - for encoder in &self.encoders { - // The ownership location of tlas's depends on where the command encoder - // came from. If it is the staging command encoder on the queue, it is - // in the pending buffer list. If it came from a user command encoder, - // it is in the tracker. - - if encoder.trackers.tlas_s.contains(tlas) { - return true; - } - - if encoder.pending_tlas_s.contains_key(&tlas.tracker_index()) { - return true; - } - } - - false - } } #[derive(Clone, Debug, Error)] @@ -211,15 +169,9 @@ impl LifetimeTracker { } /// Start tracking resources associated with a new queue submission. - pub fn track_submission( - &mut self, - index: SubmissionIndex, - temp_resources: impl Iterator, - encoders: Vec, - ) { + pub fn track_submission(&mut self, index: SubmissionIndex, encoders: Vec) { self.active.push(ActiveSubmission { index, - temp_resources: temp_resources.collect(), mapped: Vec::new(), encoders, work_done_closures: SmallVec::new(), @@ -257,34 +209,6 @@ impl LifetimeTracker { }) } - /// Returns the submission index of the most recent submission that uses the - /// given blas. - pub fn get_blas_latest_submission_index(&self, blas: &Blas) -> Option { - // We iterate in reverse order, so that we can bail out early as soon - // as we find a hit. - self.active.iter().rev().find_map(|submission| { - if submission.contains_blas(blas) { - Some(submission.index) - } else { - None - } - }) - } - - /// Returns the submission index of the most recent submission that uses the - /// given tlas. - pub fn get_tlas_latest_submission_index(&self, tlas: &Tlas) -> Option { - // We iterate in reverse order, so that we can bail out early as soon - // as we find a hit. - self.active.iter().rev().find_map(|submission| { - if submission.contains_tlas(tlas) { - Some(submission.index) - } else { - None - } - }) - } - /// Returns the submission index of the most recent submission that uses the /// given texture. pub fn get_texture_latest_submission_index( @@ -340,7 +264,6 @@ impl LifetimeTracker { profiling::scope!("drop command buffer trackers"); drop(encoder); } - drop(a.temp_resources); work_done_closures.extend(a.work_done_closures); } work_done_closures @@ -355,7 +278,12 @@ impl LifetimeTracker { .active .iter_mut() .find(|a| a.index == last_submit_index) - .map(|a| &mut a.temp_resources); + .map(|a| { + // Because this resource's `last_submit_index` matches `a.index`, + // we know that we must have done something with the resource, + // so `a.encoders` should not be empty. + &mut a.encoders.last_mut().unwrap().temp_resources + }); if let Some(resources) = resources { resources.push(temp_resource); } diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index cd6731ae04..763edf2121 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -27,7 +27,6 @@ use crate::{ use smallvec::SmallVec; -use crate::resource::{Blas, DestroyedAccelerationStructure, Tlas}; use crate::scratch::ScratchBuffer; use std::{ iter, @@ -257,7 +256,6 @@ pub enum TempResource { ScratchBuffer(ScratchBuffer), DestroyedBuffer(DestroyedBuffer), DestroyedTexture(DestroyedTexture), - DestroyedAccelerationStructure(DestroyedAccelerationStructure), } /// A series of raw [`CommandBuffer`]s that have been submitted to a @@ -268,15 +266,12 @@ pub enum TempResource { pub(crate) struct EncoderInFlight { inner: crate::command::CommandEncoder, pub(crate) trackers: Tracker, + pub(crate) temp_resources: Vec, /// These are the buffers that have been tracked by `PendingWrites`. pub(crate) pending_buffers: FastHashMap>, /// These are the textures that have been tracked by `PendingWrites`. pub(crate) pending_textures: FastHashMap>, - /// These are the BLASes that have been tracked by `PendingWrites`. - pub(crate) pending_blas_s: FastHashMap>, - /// These are the TLASes that have been tracked by `PendingWrites`. - pub(crate) pending_tlas_s: FastHashMap>, } /// A private command encoder for writes made directly on the device @@ -314,8 +309,6 @@ pub(crate) struct PendingWrites { temp_resources: Vec, dst_buffers: FastHashMap>, dst_textures: FastHashMap>, - dst_blas_s: FastHashMap>, - dst_tlas_s: FastHashMap>, } impl PendingWrites { @@ -326,8 +319,6 @@ impl PendingWrites { temp_resources: Vec::new(), dst_buffers: FastHashMap::default(), dst_textures: FastHashMap::default(), - dst_blas_s: FastHashMap::default(), - dst_tlas_s: FastHashMap::default(), } } @@ -349,22 +340,6 @@ impl PendingWrites { self.dst_textures.contains_key(&texture.tracker_index()) } - pub fn insert_blas(&mut self, blas: &Arc) { - self.dst_blas_s.insert(blas.tracker_index(), blas.clone()); - } - - pub fn insert_tlas(&mut self, tlas: &Arc) { - self.dst_tlas_s.insert(tlas.tracker_index(), tlas.clone()); - } - - pub fn contains_blas(&mut self, blas: &Arc) -> bool { - self.dst_blas_s.contains_key(&blas.tracker_index()) - } - - pub fn contains_tlas(&mut self, tlas: &Arc) -> bool { - self.dst_tlas_s.contains_key(&tlas.tracker_index()) - } - pub fn consume_temp(&mut self, resource: TempResource) { self.temp_resources.push(resource); } @@ -383,8 +358,6 @@ impl PendingWrites { if self.is_recording { let pending_buffers = mem::take(&mut self.dst_buffers); let pending_textures = mem::take(&mut self.dst_textures); - let pending_blas_s = mem::take(&mut self.dst_blas_s); - let pending_tlas_s = mem::take(&mut self.dst_tlas_s); let cmd_buf = unsafe { self.command_encoder.end_encoding() } .map_err(|e| device.handle_hal_error(e))?; @@ -403,10 +376,9 @@ impl PendingWrites { hal_label: None, }, trackers: Tracker::new(), + temp_resources: mem::take(&mut self.temp_resources), pending_buffers, pending_textures, - pending_blas_s, - pending_tlas_s, }; Ok(Some(encoder)) } else { @@ -1223,10 +1195,9 @@ impl Queue { active_executions.push(EncoderInFlight { inner: baked.encoder, trackers: baked.trackers, + temp_resources: baked.temp_resources, pending_buffers: FastHashMap::default(), pending_textures: FastHashMap::default(), - pending_blas_s: FastHashMap::default(), - pending_tlas_s: FastHashMap::default(), }); } @@ -1323,11 +1294,8 @@ impl Queue { profiling::scope!("cleanup"); // this will register the new submission to the life time tracker - self.lock_life().track_submission( - submit_index, - pending_writes.temp_resources.drain(..), - active_executions, - ); + self.lock_life() + .track_submission(submit_index, active_executions); drop(pending_writes); // This will schedule destruction of all resources that are no longer needed diff --git a/wgpu-core/src/device/ray_tracing.rs b/wgpu-core/src/device/ray_tracing.rs index 12afc7e6a8..0917831afa 100644 --- a/wgpu-core/src/device/ray_tracing.rs +++ b/wgpu-core/src/device/ray_tracing.rs @@ -1,12 +1,12 @@ use std::mem::ManuallyDrop; use std::sync::Arc; +use crate::api_log; #[cfg(feature = "trace")] use crate::device::trace; -use crate::lock::{rank, Mutex}; +use crate::lock::rank; use crate::resource::{Fallible, TrackingData}; use crate::snatch::Snatchable; -use crate::weak_vec::WeakVec; use crate::{ device::{Device, DeviceError}, global::Global, @@ -24,6 +24,9 @@ impl Device { blas_desc: &resource::BlasDescriptor, sizes: wgt::BlasGeometrySizeDescriptors, ) -> Result, CreateBlasError> { + self.check_is_valid()?; + self.require_features(Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE)?; + let size_info = match &sizes { wgt::BlasGeometrySizeDescriptors::Triangles { descriptors } => { let mut entries = @@ -109,6 +112,9 @@ impl Device { self: &Arc, desc: &resource::TlasDescriptor, ) -> Result, CreateTlasError> { + self.check_is_valid()?; + self.require_features(Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE)?; + let size_info = unsafe { self.raw().get_acceleration_structure_build_sizes( &hal::GetAccelerationStructureBuildSizesDescriptor { @@ -159,7 +165,6 @@ impl Device { label: desc.label.to_string(), max_instance_count: desc.max_instances, tracking_data: TrackingData::new(self.tracker_indices.tlas_s.clone()), - bind_groups: Mutex::new(rank::TLAS_BIND_GROUPS, WeakVec::new()), })) } } @@ -174,23 +179,10 @@ impl Global { ) -> (BlasId, Option, Option) { profiling::scope!("Device::create_blas"); - let hub = &self.hub; - let fid = hub.blas_s.prepare(id_in); + let fid = self.hub.blas_s.prepare(id_in); - let device_guard = hub.devices.read(); let error = 'error: { - let device = device_guard.get(device_id); - match device.check_is_valid() { - Ok(_) => {} - Err(err) => break 'error CreateBlasError::Device(err), - }; - - if !device - .features - .contains(Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE) - { - break 'error CreateBlasError::MissingFeature; - } + let device = self.hub.devices.get(device_id); #[cfg(feature = "trace")] if let Some(trace) = device.trace.lock().as_mut() { @@ -207,8 +199,8 @@ impl Global { }; let handle = blas.handle; - let id = fid.assign(Fallible::Valid(blas.clone())); - log::info!("Created blas {:?} with {:?}", id, desc); + let id = fid.assign(Fallible::Valid(blas)); + api_log!("Device::create_blas -> {id:?}"); return (id, Some(handle), None); }; @@ -225,23 +217,10 @@ impl Global { ) -> (TlasId, Option) { profiling::scope!("Device::create_tlas"); - let hub = &self.hub; - let fid = hub.tlas_s.prepare(id_in); + let fid = self.hub.tlas_s.prepare(id_in); - let device_guard = hub.devices.read(); let error = 'error: { - let device = device_guard.get(device_id); - match device.check_is_valid() { - Ok(_) => {} - Err(e) => break 'error CreateTlasError::Device(e), - } - - if !device - .features - .contains(Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE) - { - break 'error CreateTlasError::MissingFeature; - } + let device = self.hub.devices.get(device_id); #[cfg(feature = "trace")] if let Some(trace) = device.trace.lock().as_mut() { @@ -257,7 +236,7 @@ impl Global { }; let id = fid.assign(Fallible::Valid(tlas)); - log::info!("Created tlas {:?} with {:?}", id, desc); + api_log!("Device::create_tlas -> {id:?}"); return (id, None); }; @@ -266,88 +245,29 @@ impl Global { (id, Some(error)) } - pub fn blas_destroy(&self, blas_id: BlasId) -> Result<(), resource::DestroyError> { - profiling::scope!("Blas::destroy"); - log::info!("Blas::destroy {blas_id:?}"); - - let hub = &self.hub; - - let blas = hub.blas_s.get(blas_id).get()?; - let _device = &blas.device; - - #[cfg(feature = "trace")] - if let Some(trace) = _device.trace.lock().as_mut() { - trace.add(trace::Action::FreeBlas(blas_id)); - } - - blas.destroy() - } - pub fn blas_drop(&self, blas_id: BlasId) { profiling::scope!("Blas::drop"); - log::debug!("blas {:?} is dropped", blas_id); + api_log!("Blas::drop {blas_id:?}"); - let hub = &self.hub; - - let _blas = match hub.blas_s.remove(blas_id).get() { - Ok(blas) => blas, - Err(_) => { - return; - } - }; + let _blas = self.hub.blas_s.remove(blas_id); #[cfg(feature = "trace")] - { - let mut lock = _blas.device.trace.lock(); - - if let Some(t) = lock.as_mut() { + if let Ok(blas) = _blas.get() { + if let Some(t) = blas.device.trace.lock().as_mut() { t.add(trace::Action::DestroyBlas(blas_id)); } } } - pub fn tlas_destroy(&self, tlas_id: TlasId) -> Result<(), resource::DestroyError> { - profiling::scope!("Tlas::destroy"); - - let hub = &self.hub; - - log::info!("Tlas {:?} is destroyed", tlas_id); - let tlas_guard = hub.tlas_s.write(); - let tlas = tlas_guard - .get(tlas_id) - .get() - .map_err(resource::DestroyError::InvalidResource)? - .clone(); - drop(tlas_guard); - - let _device = &mut tlas.device.clone(); - - #[cfg(feature = "trace")] - if let Some(trace) = _device.trace.lock().as_mut() { - trace.add(trace::Action::FreeTlas(tlas_id)); - } - - tlas.destroy() - } - pub fn tlas_drop(&self, tlas_id: TlasId) { profiling::scope!("Tlas::drop"); - log::debug!("tlas {:?} is dropped", tlas_id); + api_log!("Tlas::drop {tlas_id:?}"); - let hub = &self.hub; - - let _tlas = match hub.tlas_s.remove(tlas_id).get() { - Ok(tlas) => tlas, - Err(_) => { - return; - } - }; + let _tlas = self.hub.tlas_s.remove(tlas_id); #[cfg(feature = "trace")] - { - let mut lock = _tlas.device.trace.lock(); - - if let Some(t) = lock.as_mut() { + if let Ok(tlas) = _tlas.get() { + if let Some(t) = tlas.device.trace.lock().as_mut() { t.add(trace::Action::DestroyTlas(tlas_id)); } } diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 838e822d50..681367735f 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -38,7 +38,7 @@ use wgt::{ math::align_to, DeviceLostReason, TextureFormat, TextureSampleType, TextureViewDimension, }; -use crate::resource::{AccelerationStructure, DestroyedResourceError, Tlas}; +use crate::resource::{AccelerationStructure, Tlas}; use std::{ borrow::Cow, mem::{self, ManuallyDrop}, @@ -2186,9 +2186,7 @@ impl Device { } } - Ok(tlas - .raw(snatch_guard) - .ok_or(DestroyedResourceError(tlas.error_ident()))?) + Ok(tlas.try_raw(snatch_guard)?) } // This function expects the provided bind group layout to be resolved diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index 2274d9e945..16902ea865 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -132,13 +132,11 @@ pub enum Action<'a> { desc: crate::resource::BlasDescriptor<'a>, sizes: wgt::BlasGeometrySizeDescriptors, }, - FreeBlas(id::BlasId), DestroyBlas(id::BlasId), CreateTlas { id: id::TlasId, desc: crate::resource::TlasDescriptor<'a>, }, - FreeTlas(id::TlasId), DestroyTlas(id::TlasId), } diff --git a/wgpu-core/src/id.rs b/wgpu-core/src/id.rs index fbf366982d..2fdfde9116 100644 --- a/wgpu-core/src/id.rs +++ b/wgpu-core/src/id.rs @@ -263,7 +263,6 @@ ids! { pub type QuerySetId QuerySet; pub type BlasId Blas; pub type TlasId Tlas; - pub type TlasInstanceId TlasInstance; } // The CommandBuffer type serves both as encoder and diff --git a/wgpu-core/src/lock/rank.rs b/wgpu-core/src/lock/rank.rs index 51c6c54318..652165ebda 100644 --- a/wgpu-core/src/lock/rank.rs +++ b/wgpu-core/src/lock/rank.rs @@ -148,7 +148,6 @@ define_lock_ranks! { rank BLAS_BUILT_INDEX "Blas::built_index" followed by { } rank TLAS_BUILT_INDEX "Tlas::built_index" followed by { } rank TLAS_DEPENDENCIES "Tlas::dependencies" followed by { } - rank TLAS_BIND_GROUPS "Tlas::bind_groups" followed by { } #[cfg(test)] rank PAWN "pawn" followed by { ROOK, BISHOP } diff --git a/wgpu-core/src/ray_tracing.rs b/wgpu-core/src/ray_tracing.rs index 9f4a11946d..060044cd40 100644 --- a/wgpu-core/src/ray_tracing.rs +++ b/wgpu-core/src/ray_tracing.rs @@ -9,9 +9,9 @@ use crate::{ command::CommandEncoderError, - device::DeviceError, + device::{DeviceError, MissingFeatures}, id::{BlasId, BufferId, TlasId}, - resource::CreateBufferError, + resource::{DestroyedResourceError, InvalidResourceError, MissingBufferUsageError}, }; use std::num::NonZeroU64; use std::sync::Arc; @@ -25,15 +25,13 @@ pub enum CreateBlasError { #[error(transparent)] Device(#[from] DeviceError), #[error(transparent)] - CreateBufferError(#[from] CreateBufferError), + MissingFeatures(#[from] MissingFeatures), #[error( "Only one of 'index_count' and 'index_format' was provided (either provide both or none)" )] MissingIndexData, #[error("Provided format was not within allowed formats. Provided format: {0:?}. Allowed formats: {1:?}")] InvalidVertexFormat(VertexFormat, Vec), - #[error("Features::RAY_TRACING_ACCELERATION_STRUCTURE is not enabled")] - MissingFeature, } #[derive(Clone, Debug, Error)] @@ -41,9 +39,7 @@ pub enum CreateTlasError { #[error(transparent)] Device(#[from] DeviceError), #[error(transparent)] - CreateBufferError(#[from] CreateBufferError), - #[error("Features::RAY_TRACING_ACCELERATION_STRUCTURE is not enabled")] - MissingFeature, + MissingFeatures(#[from] MissingFeatures), } /// Error encountered while attempting to do a copy on a command encoder. @@ -55,14 +51,17 @@ pub enum BuildAccelerationStructureError { #[error(transparent)] Device(#[from] DeviceError), - #[error("BufferId is invalid or destroyed")] - InvalidBufferId, + #[error(transparent)] + InvalidResource(#[from] InvalidResourceError), + + #[error(transparent)] + DestroyedResource(#[from] DestroyedResourceError), - #[error("Buffer {0:?} is invalid or destroyed")] - InvalidBuffer(ResourceErrorIdent), + #[error(transparent)] + MissingBufferUsage(#[from] MissingBufferUsageError), - #[error("Buffer {0:?} is missing `BLAS_INPUT` usage flag")] - MissingBlasInputUsageFlag(ResourceErrorIdent), + #[error(transparent)] + MissingFeatures(#[from] MissingFeatures), #[error( "Buffer {0:?} size is insufficient for provided size information (size: {1}, required: {2}" @@ -111,12 +110,6 @@ pub enum BuildAccelerationStructureError { #[error("Blas {0:?} build sizes require index buffer but none was provided")] MissingIndexBuffer(ResourceErrorIdent), - #[error("BlasId is invalid")] - InvalidBlasId, - - #[error("Blas {0:?} is destroyed")] - InvalidBlas(ResourceErrorIdent), - #[error( "Tlas {0:?} an associated instances contains an invalid custom index (more than 24bits)" )] @@ -126,21 +119,6 @@ pub enum BuildAccelerationStructureError { "Tlas {0:?} has {1} active instances but only {2} are allowed as specified by the descriptor at creation" )] TlasInstanceCountExceeded(ResourceErrorIdent, u32, u32), - - #[error("BlasId is invalid or destroyed (for instance)")] - InvalidBlasIdForInstance, - - #[error("TlasId is invalid or destroyed")] - InvalidTlasId, - - #[error("Tlas {0:?} is invalid or destroyed")] - InvalidTlas(ResourceErrorIdent), - - #[error("Features::RAY_TRACING_ACCELERATION_STRUCTURE is not enabled")] - MissingFeature, - - #[error("Buffer {0:?} is missing `TLAS_INPUT` usage flag")] - MissingTlasInputUsageFlag(ResourceErrorIdent), } #[derive(Clone, Debug, Error)] @@ -151,15 +129,15 @@ pub enum ValidateBlasActionsError { #[derive(Clone, Debug, Error)] pub enum ValidateTlasActionsError { + #[error(transparent)] + DestroyedResource(#[from] DestroyedResourceError), + #[error("Tlas {0:?} is used before it is built")] UsedUnbuilt(ResourceErrorIdent), #[error("Blas {0:?} is used before it is built (in Tlas {1:?})")] UsedUnbuiltBlas(ResourceErrorIdent, ResourceErrorIdent), - #[error("BlasId is destroyed (in Tlas {0:?})")] - InvalidBlas(ResourceErrorIdent), - #[error("Blas {0:?} is newer than the containing Tlas {1:?}")] BlasNewerThenTlas(ResourceErrorIdent, ResourceErrorIdent), } diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 0b13ad3bd0..9c2252e665 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -1889,7 +1889,10 @@ pub type BlasDescriptor<'a> = wgt::CreateBlasDescriptor>; pub type TlasDescriptor<'a> = wgt::CreateTlasDescriptor>; pub(crate) trait AccelerationStructure: Trackable { - fn raw<'a>(&'a self, guard: &'a SnatchGuard) -> Option<&'a dyn hal::DynAccelerationStructure>; + fn try_raw<'a>( + &'a self, + guard: &'a SnatchGuard, + ) -> Result<&'a dyn hal::DynAccelerationStructure, DestroyedResourceError>; } #[derive(Debug)] @@ -1920,49 +1923,14 @@ impl Drop for Blas { } impl AccelerationStructure for Blas { - fn raw<'a>(&'a self, guard: &'a SnatchGuard) -> Option<&'a dyn hal::DynAccelerationStructure> { - Some(self.raw.get(guard)?.as_ref()) - } -} - -impl Blas { - pub(crate) fn destroy(self: &Arc) -> Result<(), DestroyError> { - let device = &self.device; - - let temp = { - let mut snatch_guard = device.snatchable_lock.write(); - - let raw = match self.raw.snatch(&mut snatch_guard) { - Some(raw) => raw, - None => { - return Err(DestroyError::AlreadyDestroyed); - } - }; - - drop(snatch_guard); - - queue::TempResource::DestroyedAccelerationStructure(DestroyedAccelerationStructure { - raw: ManuallyDrop::new(raw), - device: Arc::clone(&self.device), - label: self.label().to_owned(), - bind_groups: WeakVec::new(), - }) - }; - - if let Some(queue) = device.get_queue() { - let mut pending_writes = queue.pending_writes.lock(); - if pending_writes.contains_blas(self) { - pending_writes.consume_temp(temp); - } else { - let mut life_lock = queue.lock_life(); - let last_submit_index = life_lock.get_blas_latest_submission_index(self); - if let Some(last_submit_index) = last_submit_index { - life_lock.schedule_resource_destruction(temp, last_submit_index); - } - } - } - - Ok(()) + fn try_raw<'a>( + &'a self, + guard: &'a SnatchGuard, + ) -> Result<&'a dyn hal::DynAccelerationStructure, DestroyedResourceError> { + self.raw + .get(guard) + .map(|raw| raw.as_ref()) + .ok_or_else(|| DestroyedResourceError(self.error_ident())) } } @@ -1986,7 +1954,6 @@ pub struct Tlas { /// The `label` from the descriptor used to create the resource. pub(crate) label: String, pub(crate) tracking_data: TrackingData, - pub(crate) bind_groups: Mutex>, } impl Drop for Tlas { @@ -2003,8 +1970,14 @@ impl Drop for Tlas { } impl AccelerationStructure for Tlas { - fn raw<'a>(&'a self, guard: &'a SnatchGuard) -> Option<&'a dyn hal::DynAccelerationStructure> { - Some(self.raw.get(guard)?.as_ref()) + fn try_raw<'a>( + &'a self, + guard: &'a SnatchGuard, + ) -> Result<&'a dyn hal::DynAccelerationStructure, DestroyedResourceError> { + self.raw + .get(guard) + .map(|raw| raw.as_ref()) + .ok_or_else(|| DestroyedResourceError(self.error_ident())) } } @@ -2013,76 +1986,3 @@ crate::impl_labeled!(Tlas); crate::impl_parent_device!(Tlas); crate::impl_storage_item!(Tlas); crate::impl_trackable!(Tlas); - -impl Tlas { - pub(crate) fn destroy(self: &Arc) -> Result<(), DestroyError> { - let device = &self.device; - - let temp = { - let mut snatch_guard = device.snatchable_lock.write(); - - let raw = match self.raw.snatch(&mut snatch_guard) { - Some(raw) => raw, - None => { - return Err(DestroyError::AlreadyDestroyed); - } - }; - - drop(snatch_guard); - - queue::TempResource::DestroyedAccelerationStructure(DestroyedAccelerationStructure { - raw: ManuallyDrop::new(raw), - device: Arc::clone(&self.device), - label: self.label().to_owned(), - bind_groups: mem::take(&mut self.bind_groups.lock()), - }) - }; - - if let Some(queue) = device.get_queue() { - let mut pending_writes = queue.pending_writes.lock(); - if pending_writes.contains_tlas(self) { - pending_writes.consume_temp(temp); - } else { - let mut life_lock = queue.lock_life(); - let last_submit_index = life_lock.get_tlas_latest_submission_index(self); - if let Some(last_submit_index) = last_submit_index { - life_lock.schedule_resource_destruction(temp, last_submit_index); - } - } - } - - Ok(()) - } -} - -#[derive(Debug)] -pub struct DestroyedAccelerationStructure { - raw: ManuallyDrop>, - device: Arc, - label: String, - // only filled if the acceleration structure is a TLAS - bind_groups: WeakVec, -} - -impl DestroyedAccelerationStructure { - pub fn label(&self) -> &dyn Debug { - &self.label - } -} - -impl Drop for DestroyedAccelerationStructure { - fn drop(&mut self) { - let mut deferred = self.device.deferred_destroy.lock(); - deferred.push(DeferredDestroy::BindGroups(mem::take( - &mut self.bind_groups, - ))); - drop(deferred); - - resource_log!("Destroy raw Buffer (destroyed) {:?}", self.label()); - // SAFETY: We are in the Drop impl and we don't use self.raw anymore after this point. - let raw = unsafe { ManuallyDrop::take(&mut self.raw) }; - unsafe { - hal::DynDevice::destroy_acceleration_structure(self.device.raw(), raw); - } - } -} diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index 261bb0458e..a0b91be5e6 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -98,7 +98,6 @@ Device <- CommandBuffer = insert(device.start, device.end, buffer.start, buffer. mod buffer; mod metadata; mod range; -mod ray_tracing; mod stateless; mod texture; @@ -113,7 +112,6 @@ use crate::{ use std::{fmt, ops, sync::Arc}; use thiserror::Error; -use crate::track::ray_tracing::AccelerationStructureTracker; pub(crate) use buffer::{ BufferBindGroupState, BufferTracker, BufferUsageScope, DeviceBufferTracker, }; @@ -602,8 +600,8 @@ impl DeviceTracker { pub(crate) struct Tracker { pub buffers: BufferTracker, pub textures: TextureTracker, - pub blas_s: AccelerationStructureTracker, - pub tlas_s: AccelerationStructureTracker, + pub blas_s: StatelessTracker, + pub tlas_s: StatelessTracker, pub views: StatelessTracker, pub bind_groups: StatelessTracker, pub compute_pipelines: StatelessTracker, @@ -617,8 +615,8 @@ impl Tracker { Self { buffers: BufferTracker::new(), textures: TextureTracker::new(), - blas_s: AccelerationStructureTracker::new(), - tlas_s: AccelerationStructureTracker::new(), + blas_s: StatelessTracker::new(), + tlas_s: StatelessTracker::new(), views: StatelessTracker::new(), bind_groups: StatelessTracker::new(), compute_pipelines: StatelessTracker::new(), diff --git a/wgpu-core/src/track/ray_tracing.rs b/wgpu-core/src/track/ray_tracing.rs deleted file mode 100644 index c344526dfb..0000000000 --- a/wgpu-core/src/track/ray_tracing.rs +++ /dev/null @@ -1,81 +0,0 @@ -use crate::resource::AccelerationStructure; -use crate::track::metadata::ResourceMetadata; -use crate::track::ResourceUses; -use hal::AccelerationStructureUses; -use std::sync::Arc; -use wgt::strict_assert; - -pub(crate) struct AccelerationStructureTracker { - start: Vec, - end: Vec, - - metadata: ResourceMetadata>, -} - -impl AccelerationStructureTracker { - pub fn new() -> Self { - Self { - start: Vec::new(), - end: Vec::new(), - - metadata: ResourceMetadata::new(), - } - } - - fn tracker_assert_in_bounds(&self, index: usize) { - strict_assert!(index < self.start.len()); - strict_assert!(index < self.end.len()); - self.metadata.tracker_assert_in_bounds(index); - } - - /// Sets the size of all the vectors inside the tracker. - /// - /// Must be called with the highest possible Buffer ID before - /// all unsafe functions are called. - pub fn set_size(&mut self, size: usize) { - self.start.resize(size, AccelerationStructureUses::empty()); - self.end.resize(size, AccelerationStructureUses::empty()); - - self.metadata.set_size(size); - } - - /// Extend the vectors to let the given index be valid. - fn allow_index(&mut self, index: usize) { - if index >= self.start.len() { - self.set_size(index + 1); - } - } - - /// Returns true if the given buffer is tracked. - pub fn contains(&self, acceleration_structure: &T) -> bool { - self.metadata - .contains(acceleration_structure.tracker_index().as_usize()) - } - - /// Inserts a single resource into the resource tracker. - pub fn set_single(&mut self, resource: Arc) { - let index: usize = resource.tracker_index().as_usize(); - - self.allow_index(index); - - self.tracker_assert_in_bounds(index); - } -} - -impl ResourceUses for AccelerationStructureUses { - const EXCLUSIVE: Self = Self::empty(); - - type Selector = (); - - fn bits(self) -> u16 { - Self::bits(&self) as u16 - } - - fn all_ordered(self) -> bool { - true - } - - fn any_exclusive(self) -> bool { - self.intersects(Self::EXCLUSIVE) - } -} diff --git a/wgpu/src/api/blas.rs b/wgpu/src/api/blas.rs index 57f2f869d4..ea63b17811 100644 --- a/wgpu/src/api/blas.rs +++ b/wgpu/src/api/blas.rs @@ -33,8 +33,7 @@ static_assertions::assert_impl_all!(CreateBlasDescriptor<'_>: Send, Sync); /// /// Each one contains: /// - A reference to a BLAS, this ***must*** be interacted with using [TlasInstance::new] or [TlasInstance::set_blas], a -/// TlasInstance that references a BLAS keeps that BLAS from being dropped, but if the BLAS is explicitly destroyed (e.g. -/// using [Blas::destroy]) the TlasInstance becomes invalid +/// TlasInstance that references a BLAS keeps that BLAS from being dropped /// - A user accessible transformation matrix /// - A user accessible mask /// - A user accessible custom index @@ -148,10 +147,6 @@ impl Blas { pub fn handle(&self) -> Option { self.handle } - /// Destroy the associated native resources as soon as possible. - pub fn destroy(&self) { - self.inner.destroy(); - } } /// Context version of [BlasTriangleGeometry]. diff --git a/wgpu/src/api/tlas.rs b/wgpu/src/api/tlas.rs index b260951152..c7a80ef635 100644 --- a/wgpu/src/api/tlas.rs +++ b/wgpu/src/api/tlas.rs @@ -31,13 +31,6 @@ static_assertions::assert_impl_all!(Tlas: WasmNotSendSync); crate::cmp::impl_eq_ord_hash_proxy!(Tlas => .shared.inner); -impl Tlas { - /// Destroy the associated native resources as soon as possible. - pub fn destroy(&self) { - self.shared.inner.destroy(); - } -} - /// Entry for a top level acceleration structure build. /// Used with raw instance buffers for an unvalidated builds. /// See [TlasPackage] for the safe version. diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index f9bf88eed1..9c11a129c2 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -2744,22 +2744,14 @@ impl Drop for WebTexture { } } -impl dispatch::BlasInterface for WebBlas { - fn destroy(&self) { - unimplemented!("Raytracing not implemented for web"); - } -} +impl dispatch::BlasInterface for WebBlas {} impl Drop for WebBlas { fn drop(&mut self) { // no-op } } -impl dispatch::TlasInterface for WebTlas { - fn destroy(&self) { - unimplemented!("Raytracing not implemented for web"); - } -} +impl dispatch::TlasInterface for WebTlas {} impl Drop for WebTlas { fn drop(&mut self) { // no-op diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 1f1e248dea..1437437933 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -2004,12 +2004,7 @@ impl Drop for CoreTexture { } } -impl dispatch::BlasInterface for CoreBlas { - fn destroy(&self) { - // Per spec, no error to report. Even calling destroy multiple times is valid. - let _ = self.context.0.blas_destroy(self.id); - } -} +impl dispatch::BlasInterface for CoreBlas {} impl Drop for CoreBlas { fn drop(&mut self) { @@ -2017,12 +2012,7 @@ impl Drop for CoreBlas { } } -impl dispatch::TlasInterface for CoreTlas { - fn destroy(&self) { - // Per spec, no error to report. Even calling destroy multiple times is valid. - let _ = self.context.0.tlas_destroy(self.id); - } -} +impl dispatch::TlasInterface for CoreTlas {} impl Drop for CoreTlas { fn drop(&mut self) { diff --git a/wgpu/src/dispatch.rs b/wgpu/src/dispatch.rs index bdf57b24c8..a58decf65f 100644 --- a/wgpu/src/dispatch.rs +++ b/wgpu/src/dispatch.rs @@ -269,12 +269,8 @@ pub trait TextureInterface: CommonTraits { fn destroy(&self); } -pub trait BlasInterface: CommonTraits { - fn destroy(&self); -} -pub trait TlasInterface: CommonTraits { - fn destroy(&self); -} +pub trait BlasInterface: CommonTraits {} +pub trait TlasInterface: CommonTraits {} pub trait QuerySetInterface: CommonTraits {} pub trait PipelineLayoutInterface: CommonTraits {} pub trait RenderPipelineInterface: CommonTraits {