diff --git a/crates/libs/model/src/animation.rs b/crates/libs/model/src/animation.rs index 1a5358c..919edc2 100644 --- a/crates/libs/model/src/animation.rs +++ b/crates/libs/model/src/animation.rs @@ -315,7 +315,7 @@ pub fn load_animations(gltf_animations: GltfAnimations, data: &[Data]) -> Option let animations = gltf_animations .map(|a| map_animation(&a, data)) .collect::>(); - let total_time = animations.get(0).map_or(0.0, |a| a.total_time); + let total_time = animations.first().map_or(0.0, |a| a.total_time); Some(Animations { animations, diff --git a/crates/libs/vulkan/src/buffer.rs b/crates/libs/vulkan/src/buffer.rs index 979cdb9..be61a07 100644 --- a/crates/libs/vulkan/src/buffer.rs +++ b/crates/libs/vulkan/src/buffer.rs @@ -3,7 +3,7 @@ use ash::vk; use std::{ ffi::c_void, marker::{Send, Sync}, - mem::size_of, + mem::size_of_val, sync::Arc, }; @@ -170,7 +170,7 @@ pub fn cmd_create_device_local_buffer_with_data( usage: vk::BufferUsageFlags, data: &[T], ) -> (Buffer, Buffer) { - let size = (data.len() * size_of::()) as vk::DeviceSize; + let size = size_of_val(data) as vk::DeviceSize; let staging_buffer = create_host_visible_buffer(context, vk::BufferUsageFlags::TRANSFER_SRC, data); let buffer = Buffer::create( @@ -190,7 +190,7 @@ pub fn create_host_visible_buffer( usage: vk::BufferUsageFlags, data: &[T], ) -> Buffer { - let size = (data.len() * size_of::()) as vk::DeviceSize; + let size = size_of_val(data) as vk::DeviceSize; let mut buffer = Buffer::create( Arc::clone(context), size, diff --git a/crates/libs/vulkan/src/msaa.rs b/crates/libs/vulkan/src/msaa.rs index b06fad0..dc273a9 100644 --- a/crates/libs/vulkan/src/msaa.rs +++ b/crates/libs/vulkan/src/msaa.rs @@ -1,5 +1,6 @@ -#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Eq, Default)] pub enum MsaaSamples { + #[default] S1, S2, S4, @@ -8,9 +9,3 @@ pub enum MsaaSamples { S32, S64, } - -impl Default for MsaaSamples { - fn default() -> Self { - MsaaSamples::S1 - } -} diff --git a/crates/libs/vulkan/src/pipeline.rs b/crates/libs/vulkan/src/pipeline.rs index 1f74796..4ff238d 100644 --- a/crates/libs/vulkan/src/pipeline.rs +++ b/crates/libs/vulkan/src/pipeline.rs @@ -107,7 +107,7 @@ fn create_shader_stage_info( ) -> (ShaderModule, vk::PipelineShaderStageCreateInfo) { let extension = get_shader_file_extension(stage); let shader_path = format!("crates/viewer/shaders/{}.{}.spv", params.name, extension); - let module = ShaderModule::new(Arc::clone(context), &shader_path); + let module = ShaderModule::new(Arc::clone(context), shader_path); let mut stage_info = vk::PipelineShaderStageCreateInfo::builder() .stage(stage) diff --git a/crates/libs/vulkan/src/texture.rs b/crates/libs/vulkan/src/texture.rs index 6eb35a1..9b30b51 100644 --- a/crates/libs/vulkan/src/texture.rs +++ b/crates/libs/vulkan/src/texture.rs @@ -1,6 +1,6 @@ use super::{buffer::*, context::*, image::*, util::*}; use ash::vk; -use std::{mem::size_of, sync::Arc}; +use std::{mem::size_of_val, sync::Arc}; pub struct Texture { context: Arc, @@ -66,7 +66,7 @@ impl Texture { ) -> (Self, Buffer) { let max_mip_levels = ((width.min(height) as f32).log2().floor() + 1.0) as u32; let extent = vk::Extent2D { width, height }; - let image_size = (data.len() * size_of::()) as vk::DeviceSize; + let image_size = size_of_val(data) as vk::DeviceSize; let device = context.device(); let mut buffer = Buffer::create( @@ -81,9 +81,11 @@ impl Texture { mem_copy(ptr, data); } - let format = linear - .then_some(vk::Format::R8G8B8A8_UNORM) - .unwrap_or(vk::Format::R8G8B8A8_SRGB); + let format = if linear { + vk::Format::R8G8B8A8_UNORM + } else { + vk::Format::R8G8B8A8_SRGB + }; let image = Image::create( Arc::clone(context), @@ -159,7 +161,7 @@ impl Texture { 1 }; let extent = vk::Extent2D { width, height }; - let image_size = (data.len() * size_of::()) as vk::DeviceSize; + let image_size = size_of_val(data) as vk::DeviceSize; let device = context.device(); let mut buffer = Buffer::create( diff --git a/crates/viewer/src/camera.rs b/crates/viewer/src/camera.rs index b4f20b4..26dec58 100644 --- a/crates/viewer/src/camera.rs +++ b/crates/viewer/src/camera.rs @@ -132,8 +132,8 @@ impl Orbital { // Rotation if input.is_left_clicked() { let delta = input.cursor_delta(); - let theta = delta[0] as f32 * ROTATION_SPEED_DEG.to_radians(); - let phi = delta[1] as f32 * ROTATION_SPEED_DEG.to_radians(); + let theta = delta[0] * ROTATION_SPEED_DEG.to_radians(); + let phi = delta[1] * ROTATION_SPEED_DEG.to_radians(); self.rotate(theta, phi); } diff --git a/crates/viewer/src/renderer/mod.rs b/crates/viewer/src/renderer/mod.rs index f605798..63089ad 100644 --- a/crates/viewer/src/renderer/mod.rs +++ b/crates/viewer/src/renderer/mod.rs @@ -810,7 +810,7 @@ impl Renderer { let ao_map = self .settings .ssao_enabled - .then(|| &self.attachments.ssao_blur); + .then_some(&self.attachments.ssao_blur); if let Some(model_renderer) = self.model_renderer.as_mut() { model_renderer @@ -992,7 +992,7 @@ impl Renderer { if self.settings.ssao_enabled != enable { self.settings.ssao_enabled = enable; if let Some(renderer) = self.model_renderer.as_mut() { - let ao_map = enable.then(|| &self.attachments.ssao_blur); + let ao_map = enable.then_some(&self.attachments.ssao_blur); renderer.light_pass.set_ao_map(ao_map); } } diff --git a/crates/viewer/src/renderer/postprocess/bloom.rs b/crates/viewer/src/renderer/postprocess/bloom.rs index 52b5e7c..10ff708 100644 --- a/crates/viewer/src/renderer/postprocess/bloom.rs +++ b/crates/viewer/src/renderer/postprocess/bloom.rs @@ -183,7 +183,7 @@ impl BloomPass { // Bind descriptor sets unsafe { - let set_index = output_mip as usize; + let set_index = output_mip; device.cmd_bind_descriptor_sets( command_buffer, vk::PipelineBindPoint::GRAPHICS, @@ -329,7 +329,7 @@ impl BloomPass { // Bind descriptor sets unsafe { - let set_index = 1 + input_mip as usize; + let set_index = 1 + input_mip; device.cmd_bind_descriptor_sets( command_buffer, vk::PipelineBindPoint::GRAPHICS,