diff --git a/tests/tests/ray_tracing/mod.rs b/tests/tests/ray_tracing/mod.rs index 38390fd80a..e3440034df 100644 --- a/tests/tests/ray_tracing/mod.rs +++ b/tests/tests/ray_tracing/mod.rs @@ -1,6 +1,6 @@ use std::{iter, mem}; -use wgpu_test::{gpu_test, GpuTestConfiguration, TestingContext, TestParameters}; +use wgpu_test::{gpu_test, GpuTestConfiguration, TestParameters, TestingContext}; use rt::traits::*; use wgpu::ray_tracing as rt; diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 7b5d2a451c..6df95e9dde 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -540,12 +540,16 @@ impl Global { .extend(texture_memory_actions.register_init_action(action)); } - let used_resource = bind_group.used.acceleration_structures.used_resources().map(|tlas| { - tracker.tlas_s.add_single(&tlas_guard, tlas.as_info().id()); - crate::ray_tracing::TlasAction { - id: tlas.as_info().id(), - kind: crate::ray_tracing::TlasActionKind::Use, - } + let used_resource = bind_group + .used + .acceleration_structures + .used_resources() + .map(|tlas| { + tracker.tlas_s.add_single(&tlas_guard, tlas.as_info().id()); + crate::ray_tracing::TlasAction { + id: tlas.as_info().id(), + kind: crate::ray_tracing::TlasActionKind::Use, + } }); cmd_buf_data.tlas_actions.extend( diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 1314cfed26..3e54e0bf7e 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -25,8 +25,8 @@ use crate::hub::Hub; use crate::id::CommandBufferId; use crate::init_tracker::BufferInitTrackerAction; -use crate::resource::{Resource, ResourceInfo, ResourceType}; use crate::ray_tracing::{BlasAction, TlasAction}; +use crate::resource::{Resource, ResourceInfo, ResourceType}; use crate::track::{Tracker, UsageScope}; use crate::{ api_log, global::Global, hal_api::HalApi, id, identity::GlobalIdentityHandlerFactory, diff --git a/wgpu-core/src/command/ray_tracing.rs b/wgpu-core/src/command/ray_tracing.rs index 27349e01e9..d560af4d71 100644 --- a/wgpu-core/src/command/ray_tracing.rs +++ b/wgpu-core/src/command/ray_tracing.rs @@ -18,14 +18,14 @@ use crate::{ use wgt::{math::align_to, BufferUsages}; +use crate::ray_tracing::BlasTriangleGeometry; +use crate::resource::{Buffer, Resource, ResourceInfo, StagingBuffer}; +use crate::track::PendingTransition; use std::{cmp::max, iter, num::NonZeroU64, ops::Range, ptr}; use std::ops::Deref; use std::sync::Arc; use parking_lot::{Mutex, RwLockReadGuard}; use hal::{BufferUses, CommandEncoder, Device}; -use crate::ray_tracing::BlasTriangleGeometry; -use crate::resource::{Buffer, Resource, ResourceInfo, StagingBuffer}; -use crate::track::PendingTransition; use super::BakedCommands; @@ -108,17 +108,15 @@ impl Global { &crate::ray_tracing::TraceBlasGeometries::TriangleGeometries( ref triangle_geometries, ) => { - let iter = triangle_geometries.iter().map(|tg| { - BlasTriangleGeometry { - size: &tg.size, - vertex_buffer: tg.vertex_buffer, - index_buffer: tg.index_buffer, - transform_buffer: tg.transform_buffer, - first_vertex: tg.first_vertex, - vertex_stride: tg.vertex_stride, - index_buffer_offset: tg.index_buffer_offset, - transform_buffer_offset: tg.transform_buffer_offset, - } + let iter = triangle_geometries.iter().map(|tg| BlasTriangleGeometry { + size: &tg.size, + vertex_buffer: tg.vertex_buffer, + index_buffer: tg.index_buffer, + transform_buffer: tg.transform_buffer, + first_vertex: tg.first_vertex, + vertex_stride: tg.vertex_stride, + index_buffer_offset: tg.index_buffer_offset, + transform_buffer_offset: tg.transform_buffer_offset, }); BlasGeometries::TriangleGeometries(Box::new(iter)) } @@ -133,7 +131,14 @@ impl Global { let tlas_iter = trace_tlas.iter(); let mut input_barriers = Vec::>::new(); - let mut buf_storage = Vec::<(Arc>, Option>, Option<(Arc>, Option>)>, Option<(Arc>, Option>)>, BlasTriangleGeometry, Option>>)>::new(); + let mut buf_storage = Vec::<( + Arc>, + Option>, + Option<(Arc>, Option>)>, + Option<(Arc>, Option>)>, + BlasTriangleGeometry, + Option>> + )>::new(); let mut scratch_buffer_blas_size = 0; let mut blas_storage = Vec::<(&Blas, hal::AccelerationStructureEntries, u64)>::new(); @@ -157,7 +162,6 @@ impl Global { match entry.geometries { BlasGeometries::TriangleGeometries(triangle_geometries) => { - for (i, mesh) in triangle_geometries.enumerate() { let size_desc = match &blas.sizes { &wgt::BlasGeometrySizeDescriptors::Triangles { ref desc } => desc, @@ -176,11 +180,11 @@ impl Global { || size_desc.vertex_format != mesh.size.vertex_format || size_desc.index_count.is_none() != mesh.size.index_count.is_none() || (size_desc.index_count.is_none() - || size_desc.index_count.unwrap() < mesh.size.index_count.unwrap()) + || size_desc.index_count.unwrap() < mesh.size.index_count.unwrap()) || size_desc.index_format.is_none() != mesh.size.index_format.is_none() || (size_desc.index_format.is_none() - || size_desc.index_format.unwrap() - != mesh.size.index_format.unwrap()) + || size_desc.index_format.unwrap() + != mesh.size.index_format.unwrap()) { return Err( BuildAccelerationStructureError::IncompatibleBlasBuildSizes( @@ -228,7 +232,13 @@ impl Global { .set_single( match buffer_guard.get(index_id) { Ok(buffer) => buffer, - Err(_) => { return Err(BuildAccelerationStructureError::InvalidBuffer(index_id)) }, + Err(_) => { + return Err( + BuildAccelerationStructureError::InvalidBuffer( + index_id, + ), + ) + }, }, hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, ) @@ -251,7 +261,13 @@ impl Global { .set_single( match buffer_guard.get(transform_id) { Ok(buffer) => buffer, - Err(_) => { return Err(BuildAccelerationStructureError::InvalidBuffer(transform_id)) }, + Err(_) => { + return Err( + BuildAccelerationStructureError::InvalidBuffer( + transform_id, + ), + ) + }, }, BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, ) @@ -281,32 +297,23 @@ impl Global { BuildAccelerationStructureError::InvalidBuffer(mesh.vertex_buffer), )?; if !vertex_buffer.usage.contains(BufferUsages::BLAS_INPUT) { - return Err( - BuildAccelerationStructureError::MissingBlasInputUsageFlag( - mesh.vertex_buffer, - ), - ); + return Err(BuildAccelerationStructureError::MissingBlasInputUsageFlag( + mesh.vertex_buffer, + )); } - if let Some(barrier) = - buf.1.take().map(|pending| pending.into_hal(vertex_buffer)) - { + if let Some(barrier) = buf.1.take().map(|pending| pending.into_hal(vertex_buffer)) { input_barriers.push(barrier); } if vertex_buffer.size - < (mesh.size.vertex_count + mesh.first_vertex) as u64 - * mesh.vertex_stride + < (mesh.size.vertex_count + mesh.first_vertex) as u64 * mesh.vertex_stride { - return Err( - BuildAccelerationStructureError::InsufficientBufferSize( - mesh.vertex_buffer, - vertex_buffer.size, - (mesh.size.vertex_count + mesh.first_vertex) as u64 - * mesh.vertex_stride, - ), - ); + return Err(BuildAccelerationStructureError::InsufficientBufferSize( + mesh.vertex_buffer, + vertex_buffer.size, + (mesh.size.vertex_count + mesh.first_vertex) as u64 * mesh.vertex_stride, + )); } - let vertex_buffer_offset = - mesh.first_vertex as u64 * mesh.vertex_stride; + 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( buffer_guard.get(mesh.vertex_buffer).unwrap(), @@ -957,7 +964,14 @@ impl Global { None }; - buf_storage.push((vertex_buffer, vertex_pending, index_data, transform_data, mesh, None)) + buf_storage.push(( + vertex_buffer, + vertex_pending, + index_data, + transform_data, + mesh, + None, + )) } if let Some(last) = buf_storage.last_mut() { @@ -1007,7 +1021,7 @@ impl Global { buffer_guard.get(mesh.vertex_buffer).unwrap(), vertex_buffer_offset ..(vertex_buffer_offset - + mesh.size.vertex_count as u64 * mesh.vertex_stride), + + mesh.size.vertex_count as u64 * mesh.vertex_stride), MemoryInitKind::NeedsInitializedMemory, ), ); diff --git a/wgpu/src/context.rs b/wgpu/src/context.rs index 6dadad6204..0cd547b5ed 100644 --- a/wgpu/src/context.rs +++ b/wgpu/src/context.rs @@ -1156,7 +1156,7 @@ pub(crate) struct DeviceRequest { not(target_arch = "wasm32"), all( feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") + not(target_feature = "atomics") ) ))] pub type BufferMapCallback = Box) + Send + 'static>; @@ -1172,8 +1172,8 @@ pub type BufferMapCallback = Box) + 'sta #[cfg(any( not(target_arch = "wasm32"), all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") + feature = "fragile-send-sync-non-atomic-wasm", + not(target_feature = "atomics") ) ))] pub(crate) type AdapterRequestDeviceFuture = @@ -1181,8 +1181,8 @@ pub(crate) type AdapterRequestDeviceFuture = #[cfg(not(any( not(target_arch = "wasm32"), all( - feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") + feature = "fragile-send-sync-non-atomic-wasm", + not(target_feature = "atomics") ) )))] pub(crate) type AdapterRequestDeviceFuture = @@ -1219,7 +1219,7 @@ pub type DevicePopErrorFuture = Box> + Send>; not(target_arch = "wasm32"), all( feature = "fragile-send-sync-non-atomic-wasm", - not(target_feature = "atomics") + not(target_feature = "atomics") ) )))] pub type DevicePopErrorFuture = Box>>; diff --git a/wgpu/src/ray_tracing.rs b/wgpu/src/ray_tracing.rs index 2720f3f07a..feb2cf959e 100644 --- a/wgpu/src/ray_tracing.rs +++ b/wgpu/src/ray_tracing.rs @@ -343,7 +343,11 @@ pub trait DeviceRayTracing { /// Create a bottom level acceleration structure, used inside a top level acceleration structure for ray tracing. /// - desc: The descriptor of the acceleration structure. /// - sizes: Size descriptor limiting what can be built into the acceleration structure. - fn create_blas(&self, desc: &CreateBlasDescriptor<'_>, sizes: BlasGeometrySizeDescriptors) -> Blas; + fn create_blas( + &self, + desc: &CreateBlasDescriptor<'_>, + sizes: BlasGeometrySizeDescriptors, + ) -> Blas; /// Create a top level acceleration structure, used for ray tracing. /// - desc: The descriptor of the acceleration structure. @@ -351,7 +355,11 @@ pub trait DeviceRayTracing { } impl DeviceRayTracing for Device { - fn create_blas(&self, desc: &CreateBlasDescriptor<'_>, sizes: BlasGeometrySizeDescriptors) -> Blas { + fn create_blas( + &self, + desc: &CreateBlasDescriptor<'_>, + sizes: BlasGeometrySizeDescriptors, + ) -> Blas { let (id, handle, data) = DynContext::device_create_blas( &*self.context, &self.id, @@ -434,23 +442,25 @@ impl CommandEncoderRayTracing for CommandEncoder { let mut blas = blas.into_iter().map(|e: &BlasBuildEntry<'_>| { let geometries = match &e.geometry { BlasGeometries::TriangleGeometries(triangle_geometries) => { - let iter = triangle_geometries.iter().map(|tg: &BlasTriangleGeometry<'_>| { - DynContextBlasTriangleGeometry { - size: tg.size, - vertex_buffer: tg.vertex_buffer.id, - - index_buffer: tg.index_buffer.map(|index_buffer| index_buffer.id), - - transform_buffer: tg - .transform_buffer - .map(|transform_buffer| transform_buffer.id), - - first_vertex: tg.first_vertex, - vertex_stride: tg.vertex_stride, - index_buffer_offset: tg.index_buffer_offset, - transform_buffer_offset: tg.transform_buffer_offset, - } - }); + let iter = triangle_geometries + .iter() + .map( + |tg: &BlasTriangleGeometry<'_>| DynContextBlasTriangleGeometry { + size: tg.size, + vertex_buffer: tg.vertex_buffer.id, + + index_buffer: tg.index_buffer.map(|index_buffer| index_buffer.id), + + transform_buffer: tg + .transform_buffer + .map(|transform_buffer| transform_buffer.id), + + first_vertex: tg.first_vertex, + vertex_stride: tg.vertex_stride, + index_buffer_offset: tg.index_buffer_offset, + transform_buffer_offset: tg.transform_buffer_offset, + }, + ); DynContextBlasGeometries::TriangleGeometries(Box::new(iter)) } }; @@ -495,23 +505,25 @@ impl CommandEncoderRayTracing for CommandEncoder { let mut blas = blas.into_iter().map(|e: &BlasBuildEntry<'_>| { let geometries = match &e.geometry { BlasGeometries::TriangleGeometries(triangle_geometries) => { - let iter = triangle_geometries.iter().map(|tg: &BlasTriangleGeometry<'_>| { - DynContextBlasTriangleGeometry { - size: tg.size, - vertex_buffer: tg.vertex_buffer.id, - - index_buffer: tg.index_buffer.map(|index_buffer| index_buffer.id), - - transform_buffer: tg - .transform_buffer - .map(|transform_buffer| transform_buffer.id), - - first_vertex: tg.first_vertex, - vertex_stride: tg.vertex_stride, - index_buffer_offset: tg.index_buffer_offset, - transform_buffer_offset: tg.transform_buffer_offset, - } - }); + let iter = triangle_geometries + .iter() + .map( + |tg: &BlasTriangleGeometry<'_>| DynContextBlasTriangleGeometry { + size: tg.size, + vertex_buffer: tg.vertex_buffer.id, + + index_buffer: tg.index_buffer.map(|index_buffer| index_buffer.id), + + transform_buffer: tg + .transform_buffer + .map(|transform_buffer| transform_buffer.id), + + first_vertex: tg.first_vertex, + vertex_stride: tg.vertex_stride, + index_buffer_offset: tg.index_buffer_offset, + transform_buffer_offset: tg.transform_buffer_offset, + }, + ); DynContextBlasGeometries::TriangleGeometries(Box::new(iter)) } };