diff --git a/examples/circle/main.rs b/examples/circle/main.rs index 19acc56..21d3cbf 100644 --- a/examples/circle/main.rs +++ b/examples/circle/main.rs @@ -299,12 +299,7 @@ fn resolve_samples_into_buffer( destination_buffer: &BufferRef, ) { let blit_encoder = command_buffer.new_blit_command_encoder(); - blit_encoder.resolve_counters( - &counter_sample_buffer, - NSRange::new(0, 4), - &destination_buffer, - 0, - ); + blit_encoder.resolve_counters(&counter_sample_buffer, 0..4, &destination_buffer, 0); blit_encoder.end_encoding(); } diff --git a/examples/compute/main.rs b/examples/compute/main.rs index fbb66ca..c83a6fa 100644 --- a/examples/compute/main.rs +++ b/examples/compute/main.rs @@ -113,12 +113,7 @@ fn resolve_samples_into_buffer( destination_buffer: &BufferRef, ) { let blit_encoder = command_buffer.new_blit_command_encoder(); - blit_encoder.resolve_counters( - counter_sample_buffer, - crate::NSRange::new(0, NUM_SAMPLES), - destination_buffer, - 0, - ); + blit_encoder.resolve_counters(counter_sample_buffer, 0..NUM_SAMPLES, destination_buffer, 0); blit_encoder.end_encoding(); } diff --git a/examples/raytracing/geometry.rs b/examples/raytracing/geometry.rs index 3cca339..0de779c 100644 --- a/examples/raytracing/geometry.rs +++ b/examples/raytracing/geometry.rs @@ -235,38 +235,23 @@ impl Geometry for TriangleGeometry { self.index_buffer .as_ref() .unwrap() - .did_modify_range(NSRange::new( - 0, - self.index_buffer.as_ref().unwrap().length(), - )); + .did_modify_range(0..self.index_buffer.as_ref().unwrap().length()); self.vertex_position_buffer .as_ref() .unwrap() - .did_modify_range(NSRange::new( - 0, - self.vertex_position_buffer.as_ref().unwrap().length(), - )); + .did_modify_range(0..self.vertex_position_buffer.as_ref().unwrap().length()); self.vertex_normal_buffer .as_ref() .unwrap() - .did_modify_range(NSRange::new( - 0, - self.vertex_normal_buffer.as_ref().unwrap().length(), - )); + .did_modify_range(0..self.vertex_normal_buffer.as_ref().unwrap().length()); self.vertex_colour_buffer .as_ref() .unwrap() - .did_modify_range(NSRange::new( - 0, - self.vertex_colour_buffer.as_ref().unwrap().length(), - )); + .did_modify_range(0..self.vertex_colour_buffer.as_ref().unwrap().length()); self.per_primitive_data_buffer .as_ref() .unwrap() - .did_modify_range(NSRange::new( - 0, - self.per_primitive_data_buffer.as_ref().unwrap().length(), - )); + .did_modify_range(0..self.per_primitive_data_buffer.as_ref().unwrap().length()); self.index_buffer .as_ref() @@ -395,17 +380,11 @@ impl Geometry for SphereGeometry { self.sphere_buffer .as_ref() .unwrap() - .did_modify_range(NSRange::new( - 0, - self.sphere_buffer.as_ref().unwrap().length(), - )); + .did_modify_range(0..self.sphere_buffer.as_ref().unwrap().length()); self.bounding_box_buffer .as_ref() .unwrap() - .did_modify_range(NSRange::new( - 0, - self.bounding_box_buffer.as_ref().unwrap().length(), - )); + .did_modify_range(0..self.bounding_box_buffer.as_ref().unwrap().length()); } fn clear(&mut self) { diff --git a/examples/raytracing/renderer.rs b/examples/raytracing/renderer.rs index da82088..2522a3c 100644 --- a/examples/raytracing/renderer.rs +++ b/examples/raytracing/renderer.rs @@ -127,7 +127,7 @@ impl Renderer { get_managed_buffer_storage_mode(), ); resource_buffer.set_label("resource buffer"); - resource_buffer.did_modify_range(NSRange::new(0, resource_buffer.length())); + resource_buffer.did_modify_range(0..resource_buffer.length()); let mut primitive_acceleration_structures = Vec::new(); for i in 0..scene.geometries.len() { @@ -178,7 +178,7 @@ impl Renderer { get_managed_buffer_storage_mode(), ); instance_buffer.set_label("instance buffer"); - instance_buffer.did_modify_range(NSRange::new(0, instance_buffer.length())); + instance_buffer.did_modify_range(0..instance_buffer.length()); let accel_descriptor = InstanceAccelerationStructureDescriptor::descriptor(); accel_descriptor.set_instanced_acceleration_structures(&Array::from_owned_slice( @@ -348,10 +348,9 @@ impl Renderer { uniforms.light_count = self.scene.lights.len() as u32; - self.uniform_buffer.did_modify_range(NSRange { - location: self.uniform_buffer_offset, - length: ALIGNED_UNIFORMS_SIZE, - }); + self.uniform_buffer.did_modify_range( + self.uniform_buffer_offset..(self.uniform_buffer_offset + ALIGNED_UNIFORMS_SIZE), + ); self.uniform_buffer_index = (self.uniform_buffer_index + 1) % MAX_FRAMES_IN_FLIGHT; } diff --git a/examples/raytracing/scene.rs b/examples/raytracing/scene.rs index 095f3f8..7d068ce 100644 --- a/examples/raytracing/scene.rs +++ b/examples/raytracing/scene.rs @@ -3,7 +3,7 @@ use std::{ffi::c_void, mem::size_of, sync::Arc}; use glam::{Mat4, Vec3, Vec4}; use rand::{thread_rng, Rng}; -use metal::{Buffer, Device, NSRange}; +use metal::{Buffer, Device}; use super::{camera::Camera, geometry::*}; @@ -120,7 +120,7 @@ impl Scene { lights.len() * size_of::(), get_managed_buffer_storage_mode(), ); - lights_buffer.did_modify_range(NSRange::new(0, lights_buffer.length())); + lights_buffer.did_modify_range(0..lights_buffer.length()); lights_buffer.set_label("lights buffer"); Self { diff --git a/examples/texture/src/main.rs b/examples/texture/src/main.rs index 55db8f0..b3a0292 100644 --- a/examples/texture/src/main.rs +++ b/examples/texture/src/main.rs @@ -230,7 +230,7 @@ fn update_viewport_size_buffer(viewport_size_buffer: &Buffer, size: (u32, u32)) unsafe { std::ptr::copy(viewport_size.as_ptr(), contents as *mut u32, byte_count); } - viewport_size_buffer.did_modify_range(NSRange::new(0, byte_count)); + viewport_size_buffer.did_modify_range(0..byte_count); } fn redraw( diff --git a/examples/window/main.rs b/examples/window/main.rs index 89c023b..8fed626 100644 --- a/examples/window/main.rs +++ b/examples/window/main.rs @@ -202,10 +202,7 @@ fn main() { ); } - vbuf.did_modify_range(NSRange::new( - 0, - vertex_data.len() * mem::size_of::(), - )); + vbuf.did_modify_range(0..vertex_data.len() * mem::size_of::()); let drawable = match layer.next_drawable() { Some(drawable) => drawable, diff --git a/src/buffer.rs b/src/buffer.rs index c250c73..1a3d90c 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -25,7 +25,8 @@ impl BufferRef { unsafe { msg_send![self, contents] } } - pub fn did_modify_range(&self, range: NSRange) { + pub fn did_modify_range(&self, range: Range) { + let range: NSRange = range.into(); unsafe { msg_send![self, didModifyRange: range] } } @@ -54,7 +55,8 @@ impl BufferRef { unsafe { msg_send![self, newRemoteBufferViewForDevice: device] } } - pub fn add_debug_marker(&self, name: &str, range: NSRange) { + pub fn add_debug_marker(&self, name: &str, range: Range) { + let range: NSRange = range.into(); unsafe { let name = crate::nsstring_from_str(name); msg_send![self, addDebugMarker:name range:range] diff --git a/src/encoder.rs b/src/encoder.rs index c6d5ec8..fa2873a 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -1262,9 +1262,10 @@ impl RenderCommandEncoderRef { pub fn execute_commands_in_buffer( &self, buffer: &IndirectCommandBufferRef, - with_range: NSRange, + range: Range, ) { - unsafe { msg_send![self, executeCommandsInBuffer:buffer withRange:with_range] } + let range: NSRange = range.into(); + unsafe { msg_send![self, executeCommandsInBuffer:buffer withRange: range] } } pub fn update_fence(&self, fence: &FenceRef, after_stages: MTLRenderStages) { @@ -1300,7 +1301,8 @@ impl BlitCommandEncoderRef { unsafe { msg_send![self, synchronizeResource: resource] } } - pub fn fill_buffer(&self, destination_buffer: &BufferRef, range: NSRange, value: u8) { + pub fn fill_buffer(&self, destination_buffer: &BufferRef, range: Range, value: u8) { + let range: NSRange = range.into(); unsafe { msg_send![self, fillBuffer: destination_buffer @@ -1468,10 +1470,11 @@ impl BlitCommandEncoderRef { pub fn copy_indirect_command_buffer( &self, source: &IndirectCommandBufferRef, - source_range: NSRange, + source_range: Range, destination: &IndirectCommandBufferRef, destination_index: NSUInteger, ) { + let source_range: NSRange = source_range.into(); unsafe { msg_send![self, copyIndirectCommandBuffer: source @@ -1482,7 +1485,8 @@ impl BlitCommandEncoderRef { } } - pub fn reset_commands_in_buffer(&self, buffer: &IndirectCommandBufferRef, range: NSRange) { + pub fn reset_commands_in_buffer(&self, buffer: &IndirectCommandBufferRef, range: Range) { + let range: NSRange = range.into(); unsafe { msg_send![self, resetCommandsInBuffer: buffer @@ -1494,8 +1498,9 @@ impl BlitCommandEncoderRef { pub fn optimize_indirect_command_buffer( &self, buffer: &IndirectCommandBufferRef, - range: NSRange, + range: Range, ) { + let range: NSRange = range.into(); unsafe { msg_send![self, optimizeIndirectCommandBuffer: buffer @@ -1524,10 +1529,11 @@ impl BlitCommandEncoderRef { pub fn resolve_counters( &self, sample_buffer: &CounterSampleBufferRef, - range: crate::NSRange, + range: Range, destination_buffer: &BufferRef, destination_offset: NSUInteger, ) { + let range: NSRange = range.into(); unsafe { msg_send![self, resolveCounters: sample_buffer diff --git a/src/indirect_encoder.rs b/src/indirect_encoder.rs index 07d6cf2..407e7d7 100644 --- a/src/indirect_encoder.rs +++ b/src/indirect_encoder.rs @@ -108,7 +108,8 @@ impl IndirectCommandBufferRef { unsafe { msg_send![self, indirectComputeCommandAtIndex: index] } } - pub fn reset_with_range(&self, range: NSRange) { + pub fn reset_with_range(&self, range: Range) { + let range: NSRange = range.into(); unsafe { msg_send![self, resetWithRange: range] } } } diff --git a/src/lib.rs b/src/lib.rs index 79f6dd8..4999076 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,12 +24,13 @@ use std::{ borrow::{Borrow, ToOwned}, marker::PhantomData, mem, - ops::Deref, + ops::{Deref, Range}, os::raw::c_void, }; use foreign_types::ForeignType; -pub use icrate::Foundation::{CGFloat, NSRange, NSSize as CGSize}; +pub(crate) use icrate::Foundation::NSRange; +pub use icrate::Foundation::{CGFloat, NSSize as CGSize}; pub(crate) use objc2::encode::{Encode, Encoding, RefEncode}; use objc2::runtime::{AnyObject, Bool, Protocol}; diff --git a/src/library.rs b/src/library.rs index a3c7bcd..4ec67e8 100644 --- a/src/library.rs +++ b/src/library.rs @@ -409,8 +409,9 @@ impl FunctionConstantValuesRef { &self, values: *const c_void, ty: MTLDataType, - range: NSRange, + range: Range, ) { + let range: NSRange = range.into(); unsafe { msg_send![self, setConstantValues:values type:ty withRange:range] } } diff --git a/src/texture.rs b/src/texture.rs index 7da2abb..ecdc436 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -344,9 +344,11 @@ impl TextureRef { &self, pixel_format: MTLPixelFormat, texture_type: MTLTextureType, - mipmap_levels: NSRange, - slices: NSRange, + mipmap_levels: Range, + slices: Range, ) -> Texture { + let mipmap_levels: NSRange = mipmap_levels.into(); + let slices: NSRange = slices.into(); unsafe { msg_send![self, newTextureViewWithPixelFormat:pixel_format textureType:texture_type