From d9e915a5e649ab7ad408cbef7fb383a6875bda74 Mon Sep 17 00:00:00 2001 From: Vecvec Date: Sat, 27 Jan 2024 18:34:56 +1300 Subject: [PATCH] fix clippy and fmt --- examples/src/ray_cube_compute/mod.rs | 5 +- wgpu-core/src/command/ray_tracing.rs | 99 ++++++++++++++++++++-------- wgpu-hal/src/dx12/command.rs | 11 +++- wgpu-hal/src/dx12/device.rs | 5 +- wgpu-hal/src/empty.rs | 14 +++- wgpu-hal/src/gles/command.rs | 9 ++- wgpu-hal/src/gles/device.rs | 5 +- wgpu-hal/src/lib.rs | 14 +++- wgpu-hal/src/metal/command.rs | 6 +- wgpu-hal/src/metal/device.rs | 5 ++ wgpu-hal/src/vulkan/command.rs | 48 +++++++++----- wgpu-hal/src/vulkan/device.rs | 8 ++- wgpu-types/src/lib.rs | 2 +- wgpu/src/backend/direct.rs | 10 +-- wgpu/src/context.rs | 7 +- 15 files changed, 176 insertions(+), 72 deletions(-) diff --git a/examples/src/ray_cube_compute/mod.rs b/examples/src/ray_cube_compute/mod.rs index 806ad7b4b7..696f945372 100644 --- a/examples/src/ray_cube_compute/mod.rs +++ b/examples/src/ray_cube_compute/mod.rs @@ -5,7 +5,7 @@ use glam::{Affine3A, Mat4, Quat, Vec3}; use wgpu::util::DeviceExt; use rt::traits::*; -use wgpu::{CommandEncoderDescriptor, ray_tracing as rt, StoreOp}; +use wgpu::{ray_tracing as rt, CommandEncoderDescriptor, StoreOp}; // from cube #[repr(C)] @@ -462,8 +462,7 @@ impl crate::framework::Example for Example { let dist = 3.0; - let mut encoder = - device.create_command_encoder(&CommandEncoderDescriptor { label: None }); + let mut encoder = device.create_command_encoder(&CommandEncoderDescriptor { label: None }); encoder.build_acceleration_structures( iter::once(&rt::BlasBuildEntry { diff --git a/wgpu-core/src/command/ray_tracing.rs b/wgpu-core/src/command/ray_tracing.rs index 42cfbc06f8..e94d35c5f2 100644 --- a/wgpu-core/src/command/ray_tracing.rs +++ b/wgpu-core/src/command/ray_tracing.rs @@ -1,11 +1,24 @@ -use crate::{command::CommandBuffer, device::queue::TempResource, global::Global, hal_api::HalApi, id::{BlasId, CommandEncoderId, TlasId}, identity::GlobalIdentityHandlerFactory, init_tracker::MemoryInitKind, ray_tracing::{ - tlas_instance_into_bytes, BlasAction, BlasBuildEntry, BlasGeometries, - BuildAccelerationStructureError, TlasAction, TlasBuildEntry, TlasPackage, - ValidateBlasActionsError, ValidateTlasActionsError, -}, resource::{Blas, Tlas}, storage::Storage, FastHashSet}; - -use wgt::{math::align_to, BufferUsages, BlasGeometrySizeDescriptors}; +use crate::{ + command::CommandBuffer, + device::queue::TempResource, + global::Global, + hal_api::HalApi, + id::{BlasId, CommandEncoderId, TlasId}, + identity::GlobalIdentityHandlerFactory, + init_tracker::MemoryInitKind, + ray_tracing::{ + tlas_instance_into_bytes, BlasAction, BlasBuildEntry, BlasGeometries, + BuildAccelerationStructureError, TlasAction, TlasBuildEntry, TlasPackage, + ValidateBlasActionsError, ValidateTlasActionsError, + }, + resource::{Blas, Tlas}, + storage::Storage, + FastHashSet, +}; + +use wgt::{math::align_to, BlasGeometrySizeDescriptors, BufferUsages}; +use crate::identity::Input; use crate::ray_tracing::{BlasTriangleGeometry, CompactBlasError}; use crate::resource::{Buffer, Resource, ResourceInfo, StagingBuffer}; use crate::track::PendingTransition; @@ -14,7 +27,6 @@ use parking_lot::{Mutex, RwLock, RwLockReadGuard}; use std::ops::Deref; use std::sync::Arc; use std::{cmp::max, iter, num::NonZeroU64, ops::Range, ptr}; -use crate::identity::Input; use super::BakedCommands; @@ -22,48 +34,79 @@ use super::BakedCommands; const SCRATCH_BUFFER_ALIGNMENT: u32 = 256; impl Global { - fn internal_command_encoder_compact_blas(&self, src_blas: &Arc>, raw_device: &A::Device, cmd_buf: &Arc>) -> Result, CompactBlasError> { + fn internal_command_encoder_compact_blas( + &self, + src_blas: &Arc>, + raw_device: &A::Device, + cmd_buf: &Arc>, + ) -> Result, CompactBlasError> { profiling::scope!("CommandEncoder::compact_blas"); - let acc_struct_size = unsafe { raw_device.get_acceleration_structure_compact_size(src_blas.raw.as_ref().unwrap()) }; + let acc_struct_size = unsafe { + raw_device.get_acceleration_structure_compact_size(src_blas.raw.as_ref().unwrap()) + }; - let acc_struct = unsafe { raw_device.create_acceleration_structure(&hal::AccelerationStructureDescriptor { - label: None, - size: acc_struct_size, - format: hal::AccelerationStructureFormat::BottomLevel, - }).map_err(CompactBlasError::from)? }; + let acc_struct = unsafe { + raw_device + .create_acceleration_structure(&hal::AccelerationStructureDescriptor { + label: None, + size: acc_struct_size, + format: hal::AccelerationStructureFormat::BottomLevel, + }) + .map_err(CompactBlasError::from)? + }; let mut cmd_buf_data = cmd_buf.data.lock(); let cmd_buf_data = cmd_buf_data.as_mut().unwrap(); - let encoder = cmd_buf_data.encoder.open().map_err(CompactBlasError::from)?; + let encoder = cmd_buf_data + .encoder + .open() + .map_err(CompactBlasError::from)?; let ty = match &src_blas.sizes { - BlasGeometrySizeDescriptors::Triangles { .. } => wgt::AccelerationStructureType::Triangles, + BlasGeometrySizeDescriptors::Triangles { .. } => { + wgt::AccelerationStructureType::Triangles + } }; - unsafe { encoder.copy_acceleration_structure_to_acceleration_structure(src_blas.raw.as_ref().unwrap(), &acc_struct, hal::AccelerationStructureCopy { - copy_flags: wgt::AccelerationStructureCopy::Compact, - type_flags: ty, - }) } + unsafe { + encoder.copy_acceleration_structure_to_acceleration_structure( + src_blas.raw.as_ref().unwrap(), + &acc_struct, + hal::AccelerationStructureCopy { + copy_flags: wgt::AccelerationStructureCopy::Compact, + type_flags: ty, + }, + ) + } let handle = unsafe { raw_device.get_acceleration_structure_device_address(&acc_struct) }; let mut blas = Blas { raw: Some(acc_struct), device: src_blas.device.clone(), info: ResourceInfo::new(src_blas.info.label.as_str()), - size_info: src_blas.size_info.clone(), + size_info: src_blas.size_info, sizes: src_blas.sizes.clone(), - flags: src_blas.flags.clone(), + flags: src_blas.flags, update_mode: src_blas.update_mode, - built_index: RwLock::new(src_blas.built_index.read().clone()), + built_index: RwLock::new(*src_blas.built_index.read()), handle, }; blas.size_info.acceleration_structure_size = acc_struct_size; - log::info!("src: {}, compacted: {}", src_blas.size_info.acceleration_structure_size, blas.size_info.acceleration_structure_size); + log::info!( + "src: {}, compacted: {}", + src_blas.size_info.acceleration_structure_size, + blas.size_info.acceleration_structure_size + ); Ok(blas) } - pub fn command_encoder_compact_blas(&self, encoder_id: CommandEncoderId, blas_id: BlasId, id_in: Input) -> (BlasId, Option, Option) { + pub fn command_encoder_compact_blas( + &self, + encoder_id: CommandEncoderId, + blas_id: BlasId, + id_in: Input, + ) -> (BlasId, Option, Option) { let hub = A::hub(self); let fid = hub.blas_s.prepare::(id_in); let blas_guard = hub.blas_s.read(); @@ -73,7 +116,7 @@ impl Global { Ok(cmd_buf) => cmd_buf, Err(err) => { let id = fid.assign_error(src_blas.label().as_str()); - return (id, None, Some(CompactBlasError::from(err))) + return (id, None, Some(CompactBlasError::from(err))); } }; let device = &mut &cmd_buf.device; @@ -90,7 +133,7 @@ impl Global { let id = fid.assign_error(src_blas.label().as_str()); (id, None, Some(err)) } - } + }; } pub fn command_encoder_build_acceleration_structures_unsafe_tlas<'a, A: HalApi>( &self, diff --git a/wgpu-hal/src/dx12/command.rs b/wgpu-hal/src/dx12/command.rs index 240a686114..4c4ce72ca6 100644 --- a/wgpu-hal/src/dx12/command.rs +++ b/wgpu-hal/src/dx12/command.rs @@ -1,9 +1,9 @@ use crate::auxil::{self, dxgi::result::HResult as _}; use super::conv; +use crate::AccelerationStructureCopy; use std::{mem, ops::Range, ptr}; use winapi::um::d3d12 as d3d12_ty; -use crate::AccelerationStructureCopy; fn make_box(origin: &wgt::Origin3d, size: &crate::CopyExtent) -> d3d12_ty::D3D12_BOX { d3d12_ty::D3D12_BOX { @@ -1219,7 +1219,12 @@ impl crate::CommandEncoder for super::CommandEncoder { ) { todo!() } - unsafe fn copy_acceleration_structure_to_acceleration_structure(&mut self, _src: &super::AccelerationStructure, _dst: &super::AccelerationStructure, _copy: AccelerationStructureCopy) { + unsafe fn copy_acceleration_structure_to_acceleration_structure( + &mut self, + _src: &super::AccelerationStructure, + _dst: &super::AccelerationStructure, + _copy: AccelerationStructureCopy, + ) { todo!() } -} \ No newline at end of file +} diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index b787794eaf..2353cd0d2d 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -1589,7 +1589,10 @@ impl crate::Device for super::Device { todo!() } - unsafe fn get_acceleration_structure_compact_size(&self, _acceleration_structure: &super::AccelerationStructure) -> wgt::BufferAddress { + unsafe fn get_acceleration_structure_compact_size( + &self, + _acceleration_structure: &super::AccelerationStructure, + ) -> wgt::BufferAddress { todo!() } diff --git a/wgpu-hal/src/empty.rs b/wgpu-hal/src/empty.rs index c8752a936b..ae49098ec7 100644 --- a/wgpu-hal/src/empty.rs +++ b/wgpu-hal/src/empty.rs @@ -1,7 +1,7 @@ #![allow(unused_variables)] -use std::ops::Range; use crate::AccelerationStructureCopy; +use std::ops::Range; #[derive(Clone, Debug)] pub struct Api; @@ -251,7 +251,10 @@ impl crate::Device for Context { Default::default() } - unsafe fn get_acceleration_structure_compact_size(&self, acceleration_structure: &Resource) -> wgt::BufferAddress { + unsafe fn get_acceleration_structure_compact_size( + &self, + acceleration_structure: &Resource, + ) -> wgt::BufferAddress { Default::default() } @@ -453,6 +456,11 @@ impl crate::CommandEncoder for Encoder { ) { } - unsafe fn copy_acceleration_structure_to_acceleration_structure(&mut self, src: &Resource, dst: &Resource, copy: AccelerationStructureCopy) { + unsafe fn copy_acceleration_structure_to_acceleration_structure( + &mut self, + src: &Resource, + dst: &Resource, + copy: AccelerationStructureCopy, + ) { } } diff --git a/wgpu-hal/src/gles/command.rs b/wgpu-hal/src/gles/command.rs index c08423b0a1..ebd7be4790 100644 --- a/wgpu-hal/src/gles/command.rs +++ b/wgpu-hal/src/gles/command.rs @@ -1,7 +1,7 @@ use super::{conv, Command as C}; +use crate::AccelerationStructureCopy; use arrayvec::ArrayVec; use std::{mem, ops::Range}; -use crate::AccelerationStructureCopy; #[derive(Clone, Copy, Debug, Default)] struct TextureSlotDesc { @@ -1186,7 +1186,12 @@ impl crate::CommandEncoder for super::CommandEncoder { unimplemented!() } - unsafe fn copy_acceleration_structure_to_acceleration_structure(&mut self, _src: &(), _dst: &(), _copy: AccelerationStructureCopy) { + unsafe fn copy_acceleration_structure_to_acceleration_structure( + &mut self, + _src: &(), + _dst: &(), + _copy: AccelerationStructureCopy, + ) { unimplemented!() } } diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index c49253b3d6..dc80fd7fd3 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -1489,7 +1489,10 @@ impl crate::Device for super::Device { unimplemented!() } - unsafe fn get_acceleration_structure_compact_size(&self, _acceleration_structure: &()) -> wgt::BufferAddress { + unsafe fn get_acceleration_structure_compact_size( + &self, + _acceleration_structure: &(), + ) -> wgt::BufferAddress { todo!() } diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index bfd2a16975..9d778a8c58 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -396,7 +396,10 @@ pub trait Device: WasmNotSendSync { &self, desc: &GetAccelerationStructureBuildSizesDescriptor, ) -> AccelerationStructureBuildSizes; - unsafe fn get_acceleration_structure_compact_size(&self, acceleration_structure:&A::AccelerationStructure) -> wgt::BufferAddress; + unsafe fn get_acceleration_structure_compact_size( + &self, + acceleration_structure: &A::AccelerationStructure, + ) -> wgt::BufferAddress; unsafe fn get_acceleration_structure_device_address( &self, acceleration_structure: &A::AccelerationStructure, @@ -507,7 +510,12 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { ) where T: Iterator; - unsafe fn copy_acceleration_structure_to_acceleration_structure(&mut self, src: &A::AccelerationStructure, dst: &A::AccelerationStructure, copy: AccelerationStructureCopy); + unsafe fn copy_acceleration_structure_to_acceleration_structure( + &mut self, + src: &A::AccelerationStructure, + dst: &A::AccelerationStructure, + copy: AccelerationStructureCopy, + ); // pass common /// Sets the bind group at `index` to `group`, assuming the layout @@ -1562,7 +1570,7 @@ pub struct AccelerationStructureAABBs<'a, A: Api> { } pub struct AccelerationStructureCopy { - pub copy_flags:wgt::AccelerationStructureCopy, + pub copy_flags: wgt::AccelerationStructureCopy, pub type_flags: wgt::AccelerationStructureType, } diff --git a/wgpu-hal/src/metal/command.rs b/wgpu-hal/src/metal/command.rs index 6f1a0d9c2f..79e3060c56 100644 --- a/wgpu-hal/src/metal/command.rs +++ b/wgpu-hal/src/metal/command.rs @@ -1,5 +1,5 @@ use super::{conv, AsNative, TimestampQuerySupport}; -use crate::CommandEncoder as _; +use crate::{AccelerationStructureCopy, CommandEncoder as _}; use std::{borrow::Cow, mem, ops::Range}; // has to match `Temp::binding_sizes` @@ -379,6 +379,10 @@ impl crate::CommandEncoder for super::CommandEncoder { } } + unsafe fn copy_acceleration_structure_to_acceleration_structure(&mut self, _src: &crate::metal::Api::AccelerationStructure, _dst: &crate::metal::Api::AccelerationStructure, copy: AccelerationStructureCopy) { + unimplemented!() + } + unsafe fn begin_query(&mut self, set: &super::QuerySet, index: u32) { match set.ty { wgt::QueryType::Occlusion => { diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index d7fd06c8f3..d115cdcf37 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -5,6 +5,7 @@ use std::{ sync::{atomic, Arc}, thread, time, }; +use wgt::BufferAddress; use super::conv; use crate::auxil::map_naga_stage; @@ -1228,6 +1229,10 @@ impl crate::Device for super::Device { unimplemented!() } + unsafe fn get_acceleration_structure_compact_size(&self, acceleration_structure: &crate::metal::Api::AccelerationStructure) -> BufferAddress { + unimplemented!() + } + unsafe fn get_acceleration_structure_device_address( &self, _acceleration_structure: &super::AccelerationStructure, diff --git a/wgpu-hal/src/vulkan/command.rs b/wgpu-hal/src/vulkan/command.rs index f70aa5bce4..4febd98f54 100644 --- a/wgpu-hal/src/vulkan/command.rs +++ b/wgpu-hal/src/vulkan/command.rs @@ -3,9 +3,9 @@ use super::conv; use arrayvec::ArrayVec; use ash::{extensions::ext, vk}; +use crate::AccelerationStructureCopy; use std::{mem, ops::Range, slice}; use wgt::AccelerationStructureType; -use crate::AccelerationStructureCopy; const ALLOCATION_GRANULARITY: u32 = 16; const DST_IMAGE_LAYOUT: vk::ImageLayout = vk::ImageLayout::TRANSFER_DST_OPTIMAL; @@ -1134,7 +1134,12 @@ impl crate::CommandEncoder for super::CommandEncoder { } } - unsafe fn copy_acceleration_structure_to_acceleration_structure(&mut self, src: &super::AccelerationStructure, dst: &super::AccelerationStructure, copy: AccelerationStructureCopy) { + unsafe fn copy_acceleration_structure_to_acceleration_structure( + &mut self, + src: &super::AccelerationStructure, + dst: &super::AccelerationStructure, + copy: AccelerationStructureCopy, + ) { let ray_tracing_functions = self .device .extension_fns @@ -1143,27 +1148,38 @@ impl crate::CommandEncoder for super::CommandEncoder { .expect("Feature `RAY_TRACING` not enabled"); let structure_type = match copy.type_flags { - AccelerationStructureType::Triangles => vk::StructureType::ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR, - AccelerationStructureType::AABBs => vk::StructureType::ACCELERATION_STRUCTURE_GEOMETRY_AABBS_DATA_KHR, - AccelerationStructureType::Instances => vk::StructureType::ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR, + AccelerationStructureType::Triangles => { + vk::StructureType::ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR + } + AccelerationStructureType::AABBs => { + vk::StructureType::ACCELERATION_STRUCTURE_GEOMETRY_AABBS_DATA_KHR + } + AccelerationStructureType::Instances => { + vk::StructureType::ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR + } }; let mode = match copy.copy_flags { wgt::AccelerationStructureCopy::Clone => vk::CopyAccelerationStructureModeKHR::CLONE, - wgt::AccelerationStructureCopy::Compact => vk::CopyAccelerationStructureModeKHR::COMPACT, + wgt::AccelerationStructureCopy::Compact => { + vk::CopyAccelerationStructureModeKHR::COMPACT + } }; unsafe { - ray_tracing_functions.acceleration_structure.copy_acceleration_structure( - vk::DeferredOperationKHR::null(), - &vk::CopyAccelerationStructureInfoKHR { - s_type: structure_type, - p_next: std::ptr::null(), - src: src.raw, - dst: dst.raw, - mode, - } - ).expect("Copy Failed"); + ray_tracing_functions + .acceleration_structure + .copy_acceleration_structure( + vk::DeferredOperationKHR::null(), + &vk::CopyAccelerationStructureInfoKHR { + s_type: structure_type, + p_next: std::ptr::null(), + src: src.raw, + dst: dst.raw, + mode, + }, + ) + .expect("Copy Failed"); } } } diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index 0520c9e943..c5e7bb235c 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -2200,7 +2200,10 @@ impl crate::Device for super::Device { } } - unsafe fn get_acceleration_structure_compact_size(&self, acceleration_structure: &super::AccelerationStructure) -> wgt::BufferAddress { + unsafe fn get_acceleration_structure_compact_size( + &self, + acceleration_structure: &super::AccelerationStructure, + ) -> wgt::BufferAddress { let ray_tracing_functions = self .shared .extension_fns @@ -2217,7 +2220,8 @@ impl crate::Device for super::Device { vk::QueryType::ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR, &mut size, std::mem::size_of::(), - ).expect("getting properties failed"); + ) + .expect("getting properties failed"); } wgt::BufferAddress::from_ne_bytes(size) } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 05b8b17ddf..5ca206f35b 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -7059,7 +7059,7 @@ pub enum AccelerationStructureCopy { /// Directly duplicate an acceleration structure to another Clone, /// Duplicate and compact an acceleration structure - Compact + Compact, } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 963d1e8a17..c829771ed8 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -3139,9 +3139,9 @@ impl crate::Context for Context { fn command_encoder_compact_blas( &self, - encoder:&Self::CommandEncoderId, + encoder: &Self::CommandEncoderId, encoder_data: &Self::CommandEncoderData, - blas_id:&Self::BlasId, + blas_id: &Self::BlasId, ) -> (Self::BlasId, Option, Self::BlasData) { let global = &self.0; let (id, handle, error) = wgc::gfx_select!(encoder => global.command_encoder_compact_blas( @@ -3158,11 +3158,7 @@ impl crate::Context for Context { "Device::create_blas", ); } - ( - id, - handle, - Blas {}, - ) + (id, handle, Blas {}) } fn command_encoder_build_acceleration_structures_unsafe_tlas<'a>( diff --git a/wgpu/src/context.rs b/wgpu/src/context.rs index d4f321d3ee..179cb852a1 100644 --- a/wgpu/src/context.rs +++ b/wgpu/src/context.rs @@ -1058,7 +1058,12 @@ pub trait Context: Debug + WasmNotSendSync + Sized { fn blas_drop(&self, blas: &Self::BlasId, blas_data: &Self::BlasData); fn tlas_destroy(&self, tlas: &Self::TlasId, tlas_data: &Self::TlasData); fn tlas_drop(&self, tlas: &Self::TlasId, tlas_data: &Self::TlasData); - fn command_encoder_compact_blas(&self, encoder:&Self::CommandEncoderId, device_data: &Self::CommandEncoderData, blas_id:&Self::BlasId) -> (Self::BlasId, Option, Self::BlasData); + fn command_encoder_compact_blas( + &self, + encoder: &Self::CommandEncoderId, + device_data: &Self::CommandEncoderData, + blas_id: &Self::BlasId, + ) -> (Self::BlasId, Option, Self::BlasData); } /// Object id.