Skip to content

Commit

Permalink
fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Vecvec committed Dec 10, 2023
1 parent 99f4236 commit 5efddd7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 55 deletions.
32 changes: 16 additions & 16 deletions wgpu-core/src/command/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.trackers
.buffers
.set_single(
&*match buffer_guard.get(mesh.vertex_buffer) {
match buffer_guard.get(mesh.vertex_buffer) {
Ok(buffer) => buffer,
Err(_) => {
return Err(BuildAccelerationStructureError::InvalidBuffer(
Expand Down Expand Up @@ -226,7 +226,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.trackers
.buffers
.set_single(
&*match buffer_guard.get(index_id) {
match buffer_guard.get(index_id) {
Ok(buffer) => buffer,
Err(_) => { return Err(BuildAccelerationStructureError::InvalidBuffer(index_id)) },
},
Expand All @@ -249,7 +249,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.trackers
.buffers
.set_single(
&*match buffer_guard.get(transform_id) {
match buffer_guard.get(transform_id) {
Ok(buffer) => buffer,
Err(_) => { return Err(BuildAccelerationStructureError::InvalidBuffer(transform_id)) },
},
Expand Down Expand Up @@ -288,7 +288,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
);
}
if let Some(barrier) =
buf.1.take().map(|pending| pending.into_hal(&vertex_buffer))
buf.1.take().map(|pending| pending.into_hal(vertex_buffer))
{
input_barriers.push(barrier);
}
Expand Down Expand Up @@ -472,7 +472,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
) as u64;

blas_storage.push((
&*blas,
blas,
hal::AccelerationStructureEntries::Triangles(triangle_entries),
scratch_buffer_offset,
));
Expand All @@ -489,7 +489,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.trackers
.buffers
.set_single(
&*match buffer_guard.get(entry.instance_buffer_id) {
match buffer_guard.get(entry.instance_buffer_id) {
Ok(buffer) => buffer,
Err(_) => return Err(BuildAccelerationStructureError::InvalidBuffer(entry.instance_buffer_id, )),
},
Expand Down Expand Up @@ -554,7 +554,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
tlas_storage.push((
tlas,
hal::AccelerationStructureEntries::Instances(hal::AccelerationStructureInstances {
buffer: Some(&instance_buffer),
buffer: Some(instance_buffer),
offset: 0,
count: entry.instance_count,
}),
Expand Down Expand Up @@ -892,7 +892,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.trackers
.buffers
.set_single(
&*match buffer_guard.get(mesh.vertex_buffer) {
match buffer_guard.get(mesh.vertex_buffer) {
Ok(buffer) => buffer,
Err(_) => {
return Err(BuildAccelerationStructureError::InvalidBuffer(
Expand Down Expand Up @@ -920,7 +920,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.trackers
.buffers
.set_single(
&*match buffer_guard.get(index_id) {
match buffer_guard.get(index_id) {
Ok(buffer) => buffer,
Err(_) => { return Err(BuildAccelerationStructureError::InvalidBuffer(index_id)) },
},
Expand All @@ -943,7 +943,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.trackers
.buffers
.set_single(
&*match buffer_guard.get(transform_id) {
match buffer_guard.get(transform_id) {
Ok(buffer) => buffer,
Err(_) => { return Err(BuildAccelerationStructureError::InvalidBuffer(transform_id)) },
},
Expand Down Expand Up @@ -983,7 +983,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
);
}
if let Some(barrier) =
buf.1.take().map(|pending| pending.into_hal(&vertex_buffer))
buf.1.take().map(|pending| pending.into_hal(vertex_buffer))
{
input_barriers.push(barrier);
}
Expand Down Expand Up @@ -1167,7 +1167,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
) as u64;

blas_storage.push((
&*blas,
blas,
hal::AccelerationStructureEntries::Triangles(triangle_entries),
scratch_buffer_offset,
));
Expand Down Expand Up @@ -1540,7 +1540,7 @@ impl<A: HalApi> BakedCommands<A> {
let blas = blas_guard
.get(action.id)
.map_err(|_| ValidateBlasActionsError::InvalidBlas(action.id))?;
if *blas.built_index.read() == None {
if (*blas.built_index.read()).is_none() {
return Err(ValidateBlasActionsError::UsedUnbuilt(action.id));
}
}
Expand Down Expand Up @@ -1578,15 +1578,15 @@ impl<A: HalApi> BakedCommands<A> {
let tlas_build_index = tlas.built_index.read();
let dependencies = tlas.dependencies.read();

if *tlas_build_index == None {
if (*tlas_build_index).is_none() {
return Err(ValidateTlasActionsError::UsedUnbuilt(action.id));
}
for dependency in dependencies.deref() {
let blas = blas_guard.get(*dependency).map_err(|_| {
ValidateTlasActionsError::InvalidBlas(*dependency, action.id)
})?;
let blas_build_index = blas.built_index.read().clone();
if blas_build_index == None {
let blas_build_index = *blas.built_index.read();
if blas_build_index.is_none() {
return Err(ValidateTlasActionsError::UsedUnbuilt(action.id));
}
if blas_build_index.unwrap() > tlas_build_index.unwrap() {
Expand Down
17 changes: 7 additions & 10 deletions wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3146,7 +3146,7 @@ impl crate::Context for Context {
) {
let global = &self.0;

let blas = blas.map(|e: crate::ray_tracing::ContextBlasBuildEntry<Self>| {
let blas = blas.map(|e: crate::ray_tracing::ContextBlasBuildEntry<'_, Self>| {
let geometries = match e.geometries {
crate::ray_tracing::ContextBlasGeometries::TriangleGeometries(
triangle_geometries,
Expand Down Expand Up @@ -3204,7 +3204,7 @@ impl crate::Context for Context {
) {
let global = &self.0;

let blas = blas.map(|e: crate::ray_tracing::ContextBlasBuildEntry<Self>| {
let blas = blas.map(|e: crate::ray_tracing::ContextBlasBuildEntry<'_, Self>| {
let geometries = match e.geometries {
crate::ray_tracing::ContextBlasGeometries::TriangleGeometries(
triangle_geometries,
Expand All @@ -3231,18 +3231,15 @@ impl crate::Context for Context {
});

let tlas = tlas.into_iter().map(|e| {
let instances = e.instances.into_iter().map(
|instance: Option<crate::ray_tracing::ContextTlasInstance<_>>| {
if let Some(instance) = instance {
Some(wgc::ray_tracing::TlasInstance {
let instances = e.instances.map(
|instance: Option<crate::ray_tracing::ContextTlasInstance<'_, _>>| {
instance.map(|instance|
wgc::ray_tracing::TlasInstance {
blas_id: instance.blas_id,
transform: instance.transform,
custom_index: instance.custom_index,
mask: instance.mask,
})
} else {
None
}
})
},
);
wgc::ray_tracing::TlasPackage {
Expand Down
26 changes: 13 additions & 13 deletions wgpu/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ pub trait Context: Debug + WasmNotSendSync + Sized {
type SurfaceId: ContextId + WasmNotSendSync;
type SurfaceData: ContextData;

type BlasId: ContextId + WasmNotSend + WasmNotSync;
type BlasId: ContextId + WasmNotSendSync;
type BlasData: ContextData;
type TlasId: ContextId + WasmNotSend + WasmNotSync;
type TlasId: ContextId + WasmNotSendSync;
type TlasData: ContextData;

type SurfaceOutputDetail: WasmNotSendSync + 'static;
Expand Down Expand Up @@ -1036,14 +1036,14 @@ pub trait Context: Debug + WasmNotSendSync + Sized {
&self,
device: &Self::DeviceId,
device_data: &Self::DeviceData,
desc: &crate::ray_tracing::CreateBlasDescriptor,
desc: &crate::ray_tracing::CreateBlasDescriptor<'_>,
sizes: wgt::BlasGeometrySizeDescriptors,
) -> (Self::BlasId, Option<u64>, Self::BlasData);
fn device_create_tlas(
&self,
device: &Self::DeviceId,
device_data: &Self::DeviceData,
desc: &crate::ray_tracing::CreateTlasDescriptor,
desc: &crate::ray_tracing::CreateTlasDescriptor<'_>,
) -> (Self::TlasId, Self::TlasData);
fn command_encoder_build_acceleration_structures_unsafe_tlas<'a>(
&'a self,
Expand Down Expand Up @@ -2115,14 +2115,14 @@ pub(crate) trait DynContext: Debug + WasmNotSendSync {
&self,
device: &ObjectId,
device_data: &crate::Data,
desc: &crate::ray_tracing::CreateBlasDescriptor,
desc: &crate::ray_tracing::CreateBlasDescriptor<'_>,
sizes: wgt::BlasGeometrySizeDescriptors,
) -> (ObjectId, Option<u64>, Box<crate::Data>);
fn device_create_tlas(
&self,
device: &ObjectId,
device_data: &crate::Data,
desc: &crate::ray_tracing::CreateTlasDescriptor,
desc: &crate::ray_tracing::CreateTlasDescriptor<'_>,
) -> (ObjectId, Box<crate::Data>);
fn command_encoder_build_acceleration_structures_unsafe_tlas<'a>(
&self,
Expand All @@ -2136,7 +2136,7 @@ pub(crate) trait DynContext: Debug + WasmNotSendSync {
encoder: &ObjectId,
encoder_data: &crate::Data,
blas: &mut dyn Iterator<Item = crate::ray_tracing::DynContextBlasBuildEntry<'a>>,
tlas: &mut dyn Iterator<Item = crate::ray_tracing::DynContextTlasPackage>,
tlas: &mut dyn Iterator<Item = crate::ray_tracing::DynContextTlasPackage<'_>>,
);
fn blas_destroy(&self, blas: &ObjectId, blas_data: &crate::Data);
fn blas_drop(&self, blas: &ObjectId, blas_data: &crate::Data);
Expand Down Expand Up @@ -4160,7 +4160,7 @@ where
&self,
device: &ObjectId,
device_data: &crate::Data,
desc: &crate::ray_tracing::CreateBlasDescriptor,
desc: &crate::ray_tracing::CreateBlasDescriptor<'_>,
sizes: wgt::BlasGeometrySizeDescriptors,
) -> (ObjectId, Option<u64>, Box<crate::Data>) {
let device = <T::DeviceId>::from(*device);
Expand All @@ -4174,7 +4174,7 @@ where
&self,
device: &ObjectId,
device_data: &crate::Data,
desc: &crate::ray_tracing::CreateTlasDescriptor,
desc: &crate::ray_tracing::CreateTlasDescriptor<'_>,
) -> (ObjectId, Box<crate::Data>) {
let device = <T::DeviceId>::from(*device);
let device_data = downcast_ref(device_data);
Expand Down Expand Up @@ -4245,7 +4245,7 @@ where
encoder: &ObjectId,
encoder_data: &crate::Data,
blas: &mut dyn Iterator<Item = crate::ray_tracing::DynContextBlasBuildEntry<'a>>,
tlas: &mut dyn Iterator<Item = crate::ray_tracing::DynContextTlasPackage>,
tlas: &mut dyn Iterator<Item = crate::ray_tracing::DynContextTlasPackage<'_>>,
) {
let encoder = <T::CommandEncoderId>::from(*encoder);
let encoder_data = downcast_ref(encoder_data);
Expand Down Expand Up @@ -4279,9 +4279,9 @@ where

let tlas = tlas
.into_iter()
.map(|e: crate::ray_tracing::DynContextTlasPackage| {
let instances = e.instances.into_iter().map(
|instance: Option<crate::ray_tracing::DynContextTlasInstance>| {
.map(|e: crate::ray_tracing::DynContextTlasPackage<'_>| {
let instances = e.instances.map(
|instance: Option<crate::ray_tracing::DynContextTlasInstance<'_>>| {
instance.map(|instance| crate::ray_tracing::ContextTlasInstance {
blas_id: <T::BlasId>::from(instance.blas),
transform: instance.transform,
Expand Down
32 changes: 16 additions & 16 deletions wgpu/src/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ static_assertions::assert_impl_all!(AccelerationStructureUpdateMode: Send, Sync)

/// Descriptor to create bottom level acceleration structures.
pub type CreateBlasDescriptor<'a> = wgt::CreateBlasDescriptor<Label<'a>>;
static_assertions::assert_impl_all!(CreateBlasDescriptor: Send, Sync);
static_assertions::assert_impl_all!(CreateBlasDescriptor<'_>: Send, Sync);

/// Descriptor to create top level acceleration structures.
pub type CreateTlasDescriptor<'a> = wgt::CreateTlasDescriptor<Label<'a>>;
static_assertions::assert_impl_all!(CreateTlasDescriptor: Send, Sync);
static_assertions::assert_impl_all!(CreateTlasDescriptor<'_>: Send, Sync);

#[derive(Debug)]
/// Definition for a triangle geometry.
Expand All @@ -55,14 +55,14 @@ pub struct BlasTriangleGeometry<'a> {
/// Transform buffer offset in bytes (optional, required if transform buffer is present).
pub transform_buffer_offset: Option<wgt::BufferAddress>,
}
static_assertions::assert_impl_all!(BlasTriangleGeometry: Send, Sync);
static_assertions::assert_impl_all!(BlasTriangleGeometry<'_>: Send, Sync);

/// Geometries for a bottom level acceleration structure.
pub enum BlasGeometries<'a> {
/// Triangle geometry variant.
TriangleGeometries(Vec<BlasTriangleGeometry<'a>>),
}
static_assertions::assert_impl_all!(BlasGeometries: Send, Sync);
static_assertions::assert_impl_all!(BlasGeometries<'_>: Send, Sync);

/// Entry for a bottom level acceleration structure build.
pub struct BlasBuildEntry<'a> {
Expand All @@ -71,7 +71,7 @@ pub struct BlasBuildEntry<'a> {
/// Geometries.
pub geometry: BlasGeometries<'a>,
}
static_assertions::assert_impl_all!(BlasBuildEntry: Send, Sync);
static_assertions::assert_impl_all!(BlasBuildEntry<'_>: Send, Sync);

#[derive(Debug)]
/// Bottom level acceleration structure.
Expand Down Expand Up @@ -138,7 +138,7 @@ pub struct TlasBuildEntry<'a> {
/// Number of instances in the instance buffer.
pub instance_count: u32,
}
static_assertions::assert_impl_all!(TlasBuildEntry: Send, Sync);
static_assertions::assert_impl_all!(TlasBuildEntry<'_>: Send, Sync);

/// Safe instance for a top level acceleration structure.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -247,7 +247,7 @@ impl TlasPackage {
}

/// Get the binding resource for the underling acceleration structure, to be used in a
pub fn as_binding(&self) -> BindingResource {
pub fn as_binding(&self) -> BindingResource<'_> {
BindingResource::AccelerationStructure(&self.tlas)
}

Expand Down Expand Up @@ -337,15 +337,15 @@ 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.
fn create_tlas(&self, desc: &CreateTlasDescriptor) -> Tlas;
fn create_tlas(&self, desc: &CreateTlasDescriptor<'_>) -> Tlas;
}

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,
Expand All @@ -362,7 +362,7 @@ impl DeviceRayTracing for Device {
}
}

fn create_tlas(&self, desc: &CreateTlasDescriptor) -> Tlas {
fn create_tlas(&self, desc: &CreateTlasDescriptor<'_>) -> Tlas {
let (id, data) =
DynContext::device_create_tlas(&*self.context, &self.id, self.data.as_ref(), desc);

Expand Down Expand Up @@ -425,10 +425,10 @@ impl CommandEncoderRayTracing for CommandEncoder {
) {
let id = self.id.as_ref().unwrap();

let mut blas = blas.into_iter().map(|e: &BlasBuildEntry| {
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| {
let iter = triangle_geometries.iter().map(|tg: &BlasTriangleGeometry<'_>| {
DynContextBlasTriangleGeometry {
size: tg.size,
vertex_buffer: tg.vertex_buffer.id,
Expand Down Expand Up @@ -486,10 +486,10 @@ impl CommandEncoderRayTracing for CommandEncoder {
) {
let id = self.id.as_ref().unwrap();

let mut blas = blas.into_iter().map(|e: &BlasBuildEntry| {
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| {
let iter = triangle_geometries.iter().map(|tg: &BlasTriangleGeometry<'_>| {
DynContextBlasTriangleGeometry {
size: tg.size,
vertex_buffer: tg.vertex_buffer.id,
Expand Down Expand Up @@ -517,7 +517,7 @@ impl CommandEncoderRayTracing for CommandEncoder {

let mut tlas = tlas
.into_iter()
.map(|e: &TlasBuildEntry| DynContextTlasBuildEntry {
.map(|e: &TlasBuildEntry<'_>| DynContextTlasBuildEntry {
tlas_id: e.tlas.id,
instance_buffer_id: e.instance_buffer.id,
instance_count: e.instance_count,
Expand Down

0 comments on commit 5efddd7

Please sign in to comment.