Skip to content

Commit

Permalink
cargo clippy --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Jan 2, 2025
1 parent ef768ff commit f918248
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 44 deletions.
2 changes: 1 addition & 1 deletion examples/bindless/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn main() {
let textures = (0..BINDLESS_TEXTURE_COUNT)
.map(|i| {
heap.new_texture(&texture_descriptor)
.expect(&format!("Failed to allocate texture {}", i))
.unwrap_or_else(|| panic!("Failed to allocate texture {}", i))
})
.collect::<Vec<_>>();

Expand Down
24 changes: 12 additions & 12 deletions examples/circle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() {
device.sample_timestamps(&mut cpu_start, &mut gpu_start);
let counter_sample_buffer = create_counter_sample_buffer(&device);
let destination_buffer = device.new_buffer(
(std::mem::size_of::<u64>() * 4 as usize) as u64,
(std::mem::size_of::<u64>() * 4_usize) as u64,
MTLResourceOptions::StorageModeShared,
);
let counter_sampling_point = MTLCounterSamplingPoint::AtStageBoundary;
Expand Down Expand Up @@ -116,7 +116,7 @@ fn main() {

device.new_buffer_with_data(
vertex_data.as_ptr() as *const _,
(vertex_data.len() * mem::size_of::<AAPLVertex>()) as u64,
std::mem::size_of_val(vertex_data) as u64,
MTLResourceOptions::CPUCacheModeDefaultCache | MTLResourceOptions::StorageModeManaged,
)
};
Expand Down Expand Up @@ -152,17 +152,17 @@ fn main() {
// Obtain a renderPassDescriptor generated from the view's drawable textures.
let render_pass_descriptor = RenderPassDescriptor::new();
handle_render_pass_color_attachment(
&render_pass_descriptor,
render_pass_descriptor,
drawable.texture(),
);
handle_render_pass_sample_buffer_attachment(
&render_pass_descriptor,
render_pass_descriptor,
&counter_sample_buffer,
);

// Create a render command encoder.
let encoder = command_buffer
.new_render_command_encoder(&render_pass_descriptor);
.new_render_command_encoder(render_pass_descriptor);
encoder.set_render_pipeline_state(&pipeline_state);
// Pass in the parameter data.
encoder.set_vertex_buffer(0, Some(&vbuf), 0);
Expand All @@ -171,13 +171,13 @@ fn main() {
encoder.end_encoding();

resolve_samples_into_buffer(
&command_buffer,
command_buffer,
&counter_sample_buffer,
&destination_buffer,
);

// Schedule a present once the framebuffer is complete using the current drawable.
command_buffer.present_drawable(&drawable);
command_buffer.present_drawable(drawable);

// Finalize rendering here & push the command buffer to the GPU.
command_buffer.commit();
Expand Down Expand Up @@ -256,7 +256,7 @@ fn handle_render_pass_sample_buffer_attachment(
) {
let sample_buffer_attachment_descriptor =
descriptor.sample_buffer_attachments().object_at(0).unwrap();
sample_buffer_attachment_descriptor.set_sample_buffer(&counter_sample_buffer);
sample_buffer_attachment_descriptor.set_sample_buffer(counter_sample_buffer);
sample_buffer_attachment_descriptor.set_start_of_vertex_sample_index(0 as NSUInteger);
sample_buffer_attachment_descriptor.set_end_of_vertex_sample_index(1 as NSUInteger);
sample_buffer_attachment_descriptor.set_start_of_fragment_sample_index(2 as NSUInteger);
Expand Down Expand Up @@ -309,9 +309,9 @@ fn resolve_samples_into_buffer(
) {
let blit_encoder = command_buffer.new_blit_command_encoder();
blit_encoder.resolve_counters(
&counter_sample_buffer,
counter_sample_buffer,
crate::NSRange::new(0_u64, 4),
&destination_buffer,
destination_buffer,
0_u64,
);
blit_encoder.end_encoding();
Expand All @@ -325,7 +325,7 @@ fn handle_timestamps(
gpu_end: u64,
) {
let samples = unsafe {
std::slice::from_raw_parts(resolved_sample_buffer.contents() as *const u64, 4 as usize)
std::slice::from_raw_parts(resolved_sample_buffer.contents() as *const u64, 4_usize)
};
let vertex_pass_start = samples[0];
let vertex_pass_end = samples[1];
Expand Down Expand Up @@ -382,5 +382,5 @@ fn microseconds_between_begin(begin: u64, end: u64, gpu_time_span: u64, cpu_time
let time_span = (end as f64) - (begin as f64);
let nanoseconds = time_span / (gpu_time_span as f64) * (cpu_time_span as f64);
let microseconds = nanoseconds / 1000.0;
return microseconds;
microseconds
}
10 changes: 5 additions & 5 deletions examples/headless-render/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const VIEW_WIDTH: u64 = 512;
const VIEW_HEIGHT: u64 = 512;
const TOTAL_BYTES: usize = (VIEW_WIDTH * VIEW_HEIGHT * 4) as usize;

const VERTEX_SHADER: &'static str = "triangle_vertex";
const FRAGMENT_SHADER: &'static str = "triangle_fragment";
const VERTEX_SHADER: &str = "triangle_vertex";
const FRAGMENT_SHADER: &str = "triangle_fragment";

// [2 bytes position, 3 bytes color] * 3
#[rustfmt::skip]
Expand Down Expand Up @@ -54,10 +54,10 @@ fn main() {
let vertex_buffer = create_vertex_buffer(&device);

let render_pass_descriptor = RenderPassDescriptor::new();
initialize_color_attachment(&render_pass_descriptor, &texture);
initialize_color_attachment(render_pass_descriptor, &texture);

let command_buffer = command_queue.new_command_buffer();
let rc_encoder = command_buffer.new_render_command_encoder(&render_pass_descriptor);
let rc_encoder = command_buffer.new_render_command_encoder(render_pass_descriptor);
rc_encoder.set_render_pipeline_state(&pipeline_state);
rc_encoder.set_vertex_buffer(0, Some(&vertex_buffer), 0);
rc_encoder.draw_primitives(MTLPrimitiveType::Triangle, 0, 3);
Expand Down Expand Up @@ -100,7 +100,7 @@ fn save_image(texture: &TextureRef) {
let out_file =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/headless-render/out.png");
let file = File::create(&out_file).unwrap();
let ref mut w = BufWriter::new(file);
let w = &mut BufWriter::new(file);

let mut encoder = png::Encoder::new(w, VIEW_WIDTH as u32, VIEW_HEIGHT as u32);
encoder.set_color(ColorType::Rgba);
Expand Down
2 changes: 1 addition & 1 deletion examples/library/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use metal::*;

const PROGRAM: &'static str = "";
const PROGRAM: &str = "";

fn main() {
let device = Device::system_default().expect("no device found");
Expand Down
6 changes: 3 additions & 3 deletions examples/mesh-shader/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ fn main() {
let render_pass_descriptor = RenderPassDescriptor::new();

prepare_render_pass_descriptor(
&render_pass_descriptor,
render_pass_descriptor,
drawable.texture(),
);

let command_buffer = command_queue.new_command_buffer();
let encoder =
command_buffer.new_render_command_encoder(&render_pass_descriptor);
command_buffer.new_render_command_encoder(render_pass_descriptor);

encoder.set_render_pipeline_state(&pipeline_state);
encoder.draw_mesh_threads(
Expand All @@ -115,7 +115,7 @@ fn main() {

encoder.end_encoding();

command_buffer.present_drawable(&drawable);
command_buffer.present_drawable(drawable);
command_buffer.commit();
}
_ => (),
Expand Down
6 changes: 6 additions & 0 deletions examples/raytracing/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ pub struct Camera {
pub forward: Vec4,
}

impl Default for Camera {
fn default() -> Self {
Self::new()
}
}

impl Camera {
pub fn new() -> Self {
Self {
Expand Down
12 changes: 6 additions & 6 deletions examples/raytracing/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub trait Geometry {
pub fn compute_triangle_normal(v0: &Vec3, v1: &Vec3, v2: &Vec3) -> Vec3 {
let e1 = Vec3::normalize(*v1 - *v0);
let e2 = Vec3::normalize(*v2 - *v0);
return Vec3::cross(e1, e2);
Vec3::cross(e1, e2)
}

#[derive(Default)]
Expand All @@ -55,7 +55,7 @@ pub struct Triangle {
}

pub fn get_managed_buffer_storage_mode() -> MTLResourceOptions {
return MTLResourceOptions::StorageModeManaged;
MTLResourceOptions::StorageModeManaged
}

pub struct TriangleGeometry {
Expand Down Expand Up @@ -112,10 +112,10 @@ impl TriangleGeometry {
let first_index = self.indices.len();
let base_index = self.vertices.len() as u16;

self.indices.push(base_index + 0);
self.indices.push(base_index);
self.indices.push(base_index + 1);
self.indices.push(base_index + 2);
self.indices.push(base_index + 0);
self.indices.push(base_index);
self.indices.push(base_index + 2);
self.indices.push(base_index + 3);

Expand Down Expand Up @@ -416,14 +416,14 @@ impl Geometry for SphereGeometry {
let descriptor = AccelerationStructureBoundingBoxGeometryDescriptor::descriptor();
descriptor.set_bounding_box_buffer(Some(self.bounding_box_buffer.as_ref().unwrap()));
descriptor.set_bounding_box_count(self.spheres.len() as NSUInteger);
descriptor.set_primitive_data_buffer(Some(&self.sphere_buffer.as_ref().unwrap()));
descriptor.set_primitive_data_buffer(Some(self.sphere_buffer.as_ref().unwrap()));
descriptor.set_primitive_data_stride(size_of::<Sphere>() as NSUInteger);
descriptor.set_primitive_data_element_size(size_of::<Sphere>() as NSUInteger);
From::from(descriptor)
}

fn get_resources(&self) -> Vec<Resource> {
return vec![From::from(self.sphere_buffer.as_ref().unwrap().clone())];
vec![From::from(self.sphere_buffer.as_ref().unwrap().clone())]
}

fn get_intersection_function_name(&self) -> Option<&str> {
Expand Down
14 changes: 7 additions & 7 deletions examples/raytracing/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Renderer {
geometry_descriptor.set_intersection_function_table_offset(i as NSUInteger);
let geometry_descriptors = Array::from_owned_slice(&[geometry_descriptor]);
let accel_descriptor = PrimitiveAccelerationStructureDescriptor::descriptor();
accel_descriptor.set_geometry_descriptors(&geometry_descriptors);
accel_descriptor.set_geometry_descriptors(geometry_descriptors);
let accel_descriptor: AccelerationStructureDescriptor = From::from(accel_descriptor);
primitive_acceleration_structures.push(
Self::new_acceleration_structure_with_descriptor(
Expand All @@ -164,7 +164,7 @@ impl Renderer {
MTLAccelerationStructureInstanceOptions::None
};
instance_descriptors[instance_index].intersection_function_table_offset = 0;
instance_descriptors[instance_index].mask = instance.mask as u32;
instance_descriptors[instance_index].mask = instance.mask;
for column in 0..4 {
for row in 0..3 {
instance_descriptors[instance_index].transformation_matrix[column][row] =
Expand All @@ -182,7 +182,7 @@ impl Renderer {
instance_buffer.did_modify_range(NSRange::new(0, instance_buffer.length()));

let accel_descriptor = InstanceAccelerationStructureDescriptor::descriptor();
accel_descriptor.set_instanced_acceleration_structures(&Array::from_owned_slice(
accel_descriptor.set_instanced_acceleration_structures(Array::from_owned_slice(
&primitive_acceleration_structures,
));
accel_descriptor.set_instance_count(scene.geometry_instances.len() as NSUInteger);
Expand Down Expand Up @@ -372,8 +372,8 @@ impl Renderer {
let height = self.size.height as NSUInteger;
let threads_per_thread_group = MTLSize::new(8, 8, 1);
let thread_groups = MTLSize::new(
(width + threads_per_thread_group.width - 1) / threads_per_thread_group.width,
(height + threads_per_thread_group.height - 1) / threads_per_thread_group.height,
width.div_ceil(threads_per_thread_group.width),
height.div_ceil(threads_per_thread_group.height),
1,
);
let compute_encoder = command_buffer.new_compute_command_encoder();
Expand Down Expand Up @@ -415,7 +415,7 @@ impl Renderer {
render_encoder.set_fragment_texture(0, Some(&self.accumulation_targets[0]));
render_encoder.draw_primitives(MTLPrimitiveType::Triangle, 0, 6);
render_encoder.end_encoding();
command_buffer.present_drawable(&drawable);
command_buffer.present_drawable(drawable);
}
command_buffer.commit();
}
Expand All @@ -440,7 +440,7 @@ impl Renderer {
);
command_encoder.build_acceleration_structure(
&acceleration_structure,
&descriptor,
descriptor,
&scratch_buffer,
0,
);
Expand Down
2 changes: 1 addition & 1 deletion examples/reflection/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use metal::*;
use objc::rc::autoreleasepool;

const PROGRAM: &'static str = r"
const PROGRAM: &str = r"
#include <metal_stdlib>
using namespace metal;
Expand Down
4 changes: 2 additions & 2 deletions examples/shader-dylib/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ impl App {
{
let encoder = command_buffer.new_compute_command_encoder();
encoder.set_compute_pipeline_state(&self.image_fill_cps);
encoder.set_texture(0, Some(&drawable.texture()));
encoder.set_texture(0, Some(drawable.texture()));
encoder.dispatch_threads(threads_per_grid, threads_per_threadgroup);
encoder.end_encoding();
}

command_buffer.present_drawable(&drawable);
command_buffer.present_drawable(drawable);
command_buffer.commit();
}
}
Expand Down
12 changes: 6 additions & 6 deletions examples/window/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn main() {

let mut r = 0.0f32;

let clear_rect = vec![ClearRect {
let clear_rect = [ClearRect {
rect: Rect {
x: -1.0,
y: -1.0,
Expand Down Expand Up @@ -202,12 +202,12 @@ fn main() {
std::ptr::copy(
vertex_data.as_ptr(),
p as *mut f32,
(vertex_data.len() * mem::size_of::<f32>()) as usize,
(vertex_data.len() * mem::size_of::<f32>()),
);
}

vbuf.did_modify_range(crate::NSRange::new(
0 as u64,
0_u64,
(vertex_data.len() * mem::size_of::<f32>()) as u64,
));

Expand All @@ -219,13 +219,13 @@ fn main() {
let render_pass_descriptor = RenderPassDescriptor::new();

prepare_render_pass_descriptor(
&render_pass_descriptor,
render_pass_descriptor,
drawable.texture(),
);

let command_buffer = command_queue.new_command_buffer();
let encoder =
command_buffer.new_render_command_encoder(&render_pass_descriptor);
command_buffer.new_render_command_encoder(render_pass_descriptor);

encoder.set_scissor_rect(MTLScissorRect {
x: 20,
Expand Down Expand Up @@ -254,7 +254,7 @@ fn main() {
encoder.draw_primitives(MTLPrimitiveType::Triangle, 0, 3);
encoder.end_encoding();

command_buffer.present_drawable(&drawable);
command_buffer.present_drawable(drawable);
command_buffer.commit();

r += 0.01f32;
Expand Down

0 comments on commit f918248

Please sign in to comment.