Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-ben committed May 5, 2024
1 parent 38f4eba commit a0236f7
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion crates/libs/model/src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
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,
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/vulkan/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ash::vk;
use std::{
ffi::c_void,
marker::{Send, Sync},
mem::size_of,
mem::size_of_val,
sync::Arc,
};

Expand Down Expand Up @@ -170,7 +170,7 @@ pub fn cmd_create_device_local_buffer_with_data<A, T: Copy>(
usage: vk::BufferUsageFlags,
data: &[T],
) -> (Buffer, Buffer) {
let size = (data.len() * size_of::<T>()) 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(
Expand All @@ -190,7 +190,7 @@ pub fn create_host_visible_buffer<T: Copy>(
usage: vk::BufferUsageFlags,
data: &[T],
) -> Buffer {
let size = (data.len() * size_of::<T>()) as vk::DeviceSize;
let size = size_of_val(data) as vk::DeviceSize;
let mut buffer = Buffer::create(
Arc::clone(context),
size,
Expand Down
9 changes: 2 additions & 7 deletions crates/libs/vulkan/src/msaa.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -8,9 +9,3 @@ pub enum MsaaSamples {
S32,
S64,
}

impl Default for MsaaSamples {
fn default() -> Self {
MsaaSamples::S1
}
}
2 changes: 1 addition & 1 deletion crates/libs/vulkan/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions crates/libs/vulkan/src/texture.rs
Original file line number Diff line number Diff line change
@@ -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<Context>,
Expand Down Expand Up @@ -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::<u8>()) as vk::DeviceSize;
let image_size = size_of_val(data) as vk::DeviceSize;
let device = context.device();

let mut buffer = Buffer::create(
Expand All @@ -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),
Expand Down Expand Up @@ -159,7 +161,7 @@ impl Texture {
1
};
let extent = vk::Extent2D { width, height };
let image_size = (data.len() * size_of::<f32>()) as vk::DeviceSize;
let image_size = size_of_val(data) as vk::DeviceSize;
let device = context.device();

let mut buffer = Buffer::create(
Expand Down
4 changes: 2 additions & 2 deletions crates/viewer/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/viewer/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/viewer/src/renderer/postprocess/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a0236f7

Please sign in to comment.