From d2e9f19fff7bdca1f4f15324c1c981bd1737a52f Mon Sep 17 00:00:00 2001 From: Ken Barker Date: Sat, 30 Mar 2024 17:32:46 +0000 Subject: [PATCH] Fix clippy if_not_else issues. --- Cargo.toml | 3 +- src/command_queue.rs | 204 +++++++++--------- src/context.rs | 30 +-- src/d3d10.rs | 6 +- src/d3d11.rs | 6 +- src/device.rs | 60 +++--- src/dx9_media_sharing.rs | 30 +-- src/egl.rs | 24 +-- src/event.rs | 36 ++-- src/ext.rs | 456 +++++++++++++++++++-------------------- src/gl.rs | 72 +++---- src/kernel.rs | 84 ++++---- src/layer.rs | 18 +- src/memory.rs | 66 +++--- src/platform.rs | 6 +- src/program.rs | 78 +++---- src/sampler.rs | 24 +-- 17 files changed, 601 insertions(+), 602 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 78e8d4d..d30fc0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,9 +78,8 @@ path = "examples/clinfo.rs" [lints.clippy] enum_glob_use = "deny" +missing_errors_doc = "allow" module_name_repetitions = "allow" nursery = "deny" pedantic = "deny" -missing_errors_doc = "allow" -if_not_else = "allow" unwrap_used = "deny" diff --git a/src/command_queue.rs b/src/command_queue.rs index 8268c19..0d2e156 100644 --- a/src/command_queue.rs +++ b/src/command_queue.rs @@ -92,10 +92,10 @@ pub unsafe fn create_command_queue( ) -> Result { let mut status: cl_int = CL_INVALID_VALUE; let queue: cl_command_queue = clCreateCommandQueue(context, device, properties, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(queue) + } else { + Err(status) } } @@ -124,10 +124,10 @@ pub unsafe fn create_command_queue_with_properties( let mut status: cl_int = CL_INVALID_VALUE; let queue: cl_command_queue = clCreateCommandQueueWithProperties(context, device, properties, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(queue) + } else { + Err(status) } } @@ -144,10 +144,10 @@ pub unsafe fn create_command_queue_with_properties( #[inline] pub unsafe fn retain_command_queue(command_queue: cl_command_queue) -> Result<(), cl_int> { let status: cl_int = clRetainCommandQueue(command_queue); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -164,10 +164,10 @@ pub unsafe fn retain_command_queue(command_queue: cl_command_queue) -> Result<() #[inline] pub unsafe fn release_command_queue(command_queue: cl_command_queue) -> Result<(), cl_int> { let status: cl_int = clReleaseCommandQueue(command_queue); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -244,10 +244,10 @@ pub fn get_command_queue_info( #[inline] pub fn flush(command_queue: cl_command_queue) -> Result<(), cl_int> { let status: cl_int = unsafe { clFlush(command_queue) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -260,10 +260,10 @@ pub fn flush(command_queue: cl_command_queue) -> Result<(), cl_int> { #[inline] pub fn finish(command_queue: cl_command_queue) -> Result<(), cl_int> { let status: cl_int = unsafe { clFinish(command_queue) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -292,10 +292,10 @@ pub unsafe fn enqueue_read_buffer( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -332,10 +332,10 @@ pub unsafe fn enqueue_read_buffer_rect( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -362,10 +362,10 @@ pub unsafe fn enqueue_write_buffer( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -402,10 +402,10 @@ pub unsafe fn enqueue_write_buffer_rect( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -433,10 +433,10 @@ pub unsafe fn enqueue_fill_buffer( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -463,10 +463,10 @@ pub unsafe fn enqueue_copy_buffer( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -501,10 +501,10 @@ pub unsafe fn enqueue_copy_buffer_rect( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -535,10 +535,10 @@ pub unsafe fn enqueue_read_image( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -569,10 +569,10 @@ pub unsafe fn enqueue_write_image( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -598,10 +598,10 @@ pub unsafe fn enqueue_fill_image( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -628,10 +628,10 @@ pub unsafe fn enqueue_copy_image( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -658,10 +658,10 @@ pub unsafe fn enqueue_copy_image_to_buffer( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -688,10 +688,10 @@ pub unsafe fn enqueue_copy_buffer_to_image( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -723,10 +723,10 @@ pub unsafe fn enqueue_map_buffer( &mut event, &mut status, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -762,10 +762,10 @@ pub unsafe fn enqueue_map_image( &mut event, &mut status, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -786,10 +786,10 @@ pub unsafe fn enqueue_unmap_mem_object( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -813,10 +813,10 @@ pub unsafe fn enqueue_migrate_mem_object( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -843,10 +843,10 @@ pub unsafe fn enqueue_nd_range_kernel( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -878,10 +878,10 @@ pub unsafe fn enqueue_task( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -910,10 +910,10 @@ pub unsafe fn enqueue_native_kernel( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -931,10 +931,10 @@ pub unsafe fn enqueue_marker_with_wait_list( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -952,10 +952,10 @@ pub unsafe fn enqueue_barrier_with_wait_list( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -988,10 +988,10 @@ pub unsafe fn enqueue_svm_free( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1017,10 +1017,10 @@ pub unsafe fn enqueue_svm_mem_cpy( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1046,10 +1046,10 @@ pub unsafe fn enqueue_svm_mem_fill( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1075,10 +1075,10 @@ pub unsafe fn enqueue_svm_map( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1098,10 +1098,10 @@ pub unsafe fn enqueue_svm_unmap( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1127,10 +1127,10 @@ pub unsafe fn enqueue_svm_migrate_mem( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } diff --git a/src/context.rs b/src/context.rs index c2728ef..ea03865 100644 --- a/src/context.rs +++ b/src/context.rs @@ -67,10 +67,10 @@ pub fn create_context( &mut status, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(context) + } else { + Err(status) } } @@ -97,10 +97,10 @@ pub fn create_context_from_type( let context = unsafe { clCreateContextFromType(properties, device_type, pfn_notify, user_data, &mut status) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(context) + } else { + Err(status) } } @@ -117,10 +117,10 @@ pub fn create_context_from_type( #[inline] pub unsafe fn retain_context(context: cl_context) -> Result<(), cl_int> { let status: cl_int = clRetainContext(context); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -137,10 +137,10 @@ pub unsafe fn retain_context(context: cl_context) -> Result<(), cl_int> { #[inline] pub unsafe fn release_context(context: cl_context) -> Result<(), cl_int> { let status: cl_int = clReleaseContext(context); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -204,10 +204,10 @@ pub fn set_context_destructor_callback( user_data: *mut c_void, ) -> Result<(), cl_int> { let status: cl_int = unsafe { clSetContextDestructorCallback(context, pfn_notify, user_data) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } // #endif diff --git a/src/d3d10.rs b/src/d3d10.rs index 28dc524..6a2dbb7 100644 --- a/src/d3d10.rs +++ b/src/d3d10.rs @@ -57,10 +57,10 @@ pub unsafe fn get_supported_d3d10_texture_formats_intel( ids.as_mut_ptr(), ptr::null_mut(), ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(ids) + } else { + Err(status) } } else { Ok(Vec::default()) diff --git a/src/d3d11.rs b/src/d3d11.rs index 47925df..4805185 100644 --- a/src/d3d11.rs +++ b/src/d3d11.rs @@ -60,10 +60,10 @@ pub unsafe fn get_supported_d3d11_texture_formats_intel( ids.as_mut_ptr(), ptr::null_mut(), ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(ids) + } else { + Err(status) } } else { Ok(Vec::default()) diff --git a/src/device.rs b/src/device.rs index af7f3cb..fc72bdc 100644 --- a/src/device.rs +++ b/src/device.rs @@ -172,10 +172,10 @@ pub fn get_device_ids( ids.set_len(len); }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(ids) + } else { + Err(status) } } else { Ok(Vec::default()) @@ -448,10 +448,10 @@ pub fn get_device_info( value.as_mut_ptr().cast::(), ptr::null_mut(),) }; - if CL_SUCCESS != status { - Err(status) + if CL_SUCCESS == status { + Ok(InfoType::Uuid(value)) } else { - Ok(InfoType::Uuid(value)) + Err(status) } } @@ -466,10 +466,10 @@ pub fn get_device_info( value.as_mut_ptr().cast::(), ptr::null_mut(),) }; - if CL_SUCCESS != status { - Err(status) + if CL_SUCCESS == status { + Ok(InfoType::Luid(value)) } else { - Ok(InfoType::Luid(value)) + Err(status) } } @@ -574,10 +574,10 @@ fn count_sub_devices( &mut count, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(count) + } else { + Err(status) } } @@ -613,10 +613,10 @@ pub fn create_sub_devices( ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(ids) + } else { + Err(status) } } @@ -635,10 +635,10 @@ pub fn create_sub_devices( #[inline] pub unsafe fn retain_device(device: cl_device_id) -> Result<(), cl_int> { let status: cl_int = clRetainDevice(device); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -657,10 +657,10 @@ pub unsafe fn retain_device(device: cl_device_id) -> Result<(), cl_int> { #[inline] pub unsafe fn release_device(device: cl_device_id) -> Result<(), cl_int> { let status: cl_int = clReleaseDevice(device); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -682,10 +682,10 @@ pub fn set_default_device_command_queue( command_queue: cl_command_queue, ) -> Result<(), cl_int> { let status: cl_int = unsafe { clSetDefaultDeviceCommandQueue(context, device, command_queue) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -704,10 +704,10 @@ pub fn get_device_and_host_timer(device: cl_device_id) -> Result<[cl_ulong; 2], let mut host_timestamp: cl_ulong = 0; let status: cl_int = unsafe { clGetDeviceAndHostTimer(device, &mut device_timestamp, &mut host_timestamp) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok([device_timestamp, host_timestamp]) + } else { + Err(status) } } @@ -724,10 +724,10 @@ pub fn get_device_and_host_timer(device: cl_device_id) -> Result<[cl_ulong; 2], pub fn get_host_timer(device: cl_device_id) -> Result { let mut host_timestamp: cl_ulong = 0; let status: cl_int = unsafe { clGetHostTimer(device, &mut host_timestamp) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(host_timestamp) + } else { + Err(status) } } // #endif diff --git a/src/dx9_media_sharing.rs b/src/dx9_media_sharing.rs index e3a5fe3..da209e2 100644 --- a/src/dx9_media_sharing.rs +++ b/src/dx9_media_sharing.rs @@ -61,10 +61,10 @@ pub unsafe fn get_device_ids_from_dx9_intel( ids.as_mut_ptr(), ptr::null_mut(), ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(ids) + } else { + Err(status) } } else { Ok(Vec::default()) @@ -88,10 +88,10 @@ pub unsafe fn create_from_dx9_media_surface_intel( plane, &mut status, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -112,10 +112,10 @@ pub unsafe fn enqueue_acquire_dx9_objects_intel( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -136,10 +136,10 @@ pub unsafe fn enqueue_release_dx9_objects_intel( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -178,10 +178,10 @@ pub unsafe fn get_supported_dx9_media_surface_formats_intel( ids.as_mut_ptr(), ptr::null_mut(), ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(ids) + } else { + Err(status) } } else { Ok(Vec::default()) diff --git a/src/egl.rs b/src/egl.rs index b5531ae..ecdc7cc 100644 --- a/src/egl.rs +++ b/src/egl.rs @@ -52,10 +52,10 @@ pub unsafe fn create_from_egl_image( ) -> Result { let mut status: cl_int = CL_INVALID_VALUE; let mem = clCreateFromEGLImageKHR(context, display, image, flags, properties, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -93,10 +93,10 @@ pub unsafe fn enqueue_acquire_egl_objects( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -134,10 +134,10 @@ pub unsafe fn enqueue_release_egl_objects( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -164,9 +164,9 @@ pub unsafe fn create_event_from_egl_sync_khr( ) -> Result { let mut status: cl_int = CL_INVALID_VALUE; let event: cl_event = clCreateEventFromEGLSyncKHR(context, sync, display, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } diff --git a/src/event.rs b/src/event.rs index 6bf556c..6056c23 100644 --- a/src/event.rs +++ b/src/event.rs @@ -63,10 +63,10 @@ use std::ptr; #[allow(clippy::cast_possible_truncation)] pub fn wait_for_events(events: &[cl_event]) -> Result<(), cl_int> { let status: cl_int = unsafe { clWaitForEvents(events.len() as cl_uint, events.as_ptr()) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -120,10 +120,10 @@ pub fn get_event_info(event: cl_event, param_name: cl_event_info) -> Result Result { let mut status: cl_int = CL_INVALID_VALUE; let event: cl_event = unsafe { clCreateUserEvent(context, &mut status) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -140,10 +140,10 @@ pub fn create_user_event(context: cl_context) -> Result { #[inline] pub unsafe fn retain_event(event: cl_event) -> Result<(), cl_int> { let status: cl_int = clRetainEvent(event); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -160,10 +160,10 @@ pub unsafe fn retain_event(event: cl_event) -> Result<(), cl_int> { #[inline] pub unsafe fn release_event(event: cl_event) -> Result<(), cl_int> { let status: cl_int = clReleaseEvent(event); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -177,10 +177,10 @@ pub unsafe fn release_event(event: cl_event) -> Result<(), cl_int> { #[inline] pub fn set_user_event_status(event: cl_event, execution_status: cl_int) -> Result<(), cl_int> { let status: cl_int = unsafe { clSetUserEventStatus(event, execution_status) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -207,10 +207,10 @@ pub fn set_event_callback( user_data, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } diff --git a/src/ext.rs b/src/ext.rs index 4f0c770..d1f89ef 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -51,20 +51,20 @@ pub fn create_command_buffer_khr( &mut status, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(buffer) + } else { + Err(status) } } #[cfg(feature = "cl_khr_command_buffer")] pub fn finalize_command_buffer_khr(command_buffer: cl_command_buffer_khr) -> Result<(), cl_int> { let status: cl_int = unsafe { clFinalizeCommandBufferKHR(command_buffer) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -73,10 +73,10 @@ pub unsafe fn retain_command_buffer_khr( command_buffer: cl_command_buffer_khr, ) -> Result<(), cl_int> { let status: cl_int = clRetainCommandBufferKHR(command_buffer); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -85,10 +85,10 @@ pub unsafe fn release_command_buffer_khr( command_buffer: cl_command_buffer_khr, ) -> Result<(), cl_int> { let status: cl_int = clReleaseCommandBufferKHR(command_buffer); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -109,10 +109,10 @@ pub unsafe fn enqueue_command_buffer_khr( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -133,10 +133,10 @@ pub unsafe fn command_barrier_with_wait_list_khr( sync_point, mutable_handle, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -167,10 +167,10 @@ pub unsafe fn command_copy_buffer_khr( sync_point, mutable_handle, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -209,10 +209,10 @@ pub unsafe fn command_copy_buffer_rect_khr( sync_point, mutable_handle, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -243,10 +243,10 @@ pub unsafe fn command_copy_buffer_to_image_khr( sync_point, mutable_handle, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -277,10 +277,10 @@ pub unsafe fn command_copy_image_khr( sync_point, mutable_handle, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -311,10 +311,10 @@ pub unsafe fn command_copy_image_to_buffer_khr( sync_point, mutable_handle, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -345,10 +345,10 @@ pub unsafe fn command_fill_buffer_khr( sync_point, mutable_handle, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -377,10 +377,10 @@ pub unsafe fn command_fill_image_khr( sync_point, mutable_handle, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -413,10 +413,10 @@ pub unsafe fn command_nd_range_kernel_khr( sync_point, mutable_handle, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -443,10 +443,10 @@ pub unsafe fn command_svm_memcpy_khr( sync_point, mutable_handle, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -475,10 +475,10 @@ pub unsafe fn command_svm_mem_fill_khr( sync_point, mutable_handle, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -560,10 +560,10 @@ pub unsafe fn remap_command_buffer_khr( handles_ret, &mut errcode_ret, ); - if CL_SUCCESS != errcode_ret { - Err(errcode_ret) - } else { + if CL_SUCCESS == errcode_ret { Ok(cmd_buffer) + } else { + Err(errcode_ret) } } @@ -573,10 +573,10 @@ pub unsafe fn update_mutable_commands_khr( mutable_config: *const cl_mutable_base_config_khr, ) -> Result<(), cl_int> { let status: cl_int = clUpdateMutableCommandsKHR(command_buffer, mutable_config); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -598,10 +598,10 @@ pub unsafe fn set_mem_object_destructor_apple( user_data: *mut c_void, ) -> Result<(), cl_int> { let status: cl_int = clSetMemObjectDestructorAPPLE(memobj, pfn_notify, user_data); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -623,10 +623,10 @@ pub fn icd_get_platform_ids_khr() -> Result, cl_int> { status = clIcdGetPlatformIDsKHR(count, ids.as_mut_ptr(), ptr::null_mut()); }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(ids) + } else { + Err(status) } } else { Ok(Vec::default()) @@ -644,20 +644,20 @@ pub fn create_program_with_il_khr(context: cl_context, il: &[u8]) -> Result Result<(), cl_int> { let status = clTerminateContextKHR(context); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -670,30 +670,30 @@ pub fn create_command_queue_with_properties_khr( let mut status: cl_int = CL_INVALID_VALUE; let queue: cl_command_queue = unsafe { clCreateCommandQueueWithPropertiesKHR(context, device, properties, &mut status) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(queue) + } else { + Err(status) } } #[cfg(feature = "cl_ext_device_fission")] pub unsafe fn release_device_ext(device: cl_device_id) -> Result<(), cl_int> { let status = clReleaseDeviceEXT(device); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } #[cfg(feature = "cl_ext_device_fission")] pub unsafe fn retain_device_ext(device: cl_device_id) -> Result<(), cl_int> { let status = clRetainDeviceEXT(device); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -713,10 +713,10 @@ fn count_sub_devices_ext( &mut count, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(count) + } else { + Err(status) } } @@ -742,10 +742,10 @@ pub fn create_sub_devices_ext( ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(ids) + } else { + Err(status) } } @@ -768,10 +768,10 @@ pub unsafe fn enqueue_migrate_mem_object_ext( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -797,10 +797,10 @@ pub fn get_device_image_info_qcom( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(data) + } else { + Err(status) } } @@ -821,10 +821,10 @@ pub unsafe fn enqueue_acquire_gralloc_objects_img( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -845,10 +845,10 @@ pub unsafe fn enqueue_release_gralloc_objects_img( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -875,10 +875,10 @@ pub unsafe fn enqueue_generate_mipmap_img( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -910,10 +910,10 @@ pub fn get_kernel_sub_group_info_khr( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(data) + } else { + Err(status) } } } @@ -938,10 +938,10 @@ pub fn get_kernel_suggested_local_work_size_khr( &mut suggested_local_work_size, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(suggested_local_work_size) + } else { + Err(status) } } @@ -962,10 +962,10 @@ pub unsafe fn enqueue_acquire_external_mem_objects_khr( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -986,10 +986,10 @@ pub unsafe fn enqueue_release_external_mem_objects_khr( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1011,9 +1011,7 @@ pub fn get_semaphore_handle_for_type_khr( &mut size, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { let mut data: cl_semaphore_khr = ptr::null_mut(); let data_ptr: *mut cl_semaphore_khr = &mut data; let status: cl_int = unsafe { @@ -1026,11 +1024,13 @@ pub fn get_semaphore_handle_for_type_khr( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(data) + } else { + Err(status) } + } else { + Err(status) } } @@ -1041,10 +1041,10 @@ pub unsafe fn reimport_semaphore_sync_fd( fd: c_int, ) -> Result<(), cl_int> { let status: cl_int = clReImportSemaphoreSyncFdKHR(sema_object, reimport_props, fd); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -1056,10 +1056,10 @@ pub fn create_semaphore_with_properties_khr( let mut status: cl_int = CL_INVALID_VALUE; let semaphore: cl_semaphore_khr = unsafe { clCreateSemaphoreWithPropertiesKHR(context, sema_props, &mut status) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(semaphore) + } else { + Err(status) } } @@ -1082,10 +1082,10 @@ pub unsafe fn enqueue_wait_semaphores_khr( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1108,10 +1108,10 @@ pub unsafe fn enqueue_signal_semaphores_khr( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1129,20 +1129,20 @@ pub fn get_semaphore_info_khr( #[cfg(feature = "cl_khr_semaphore")] pub unsafe fn release_semaphore_khr(sema_object: cl_semaphore_khr) -> Result<(), cl_int> { let status: cl_int = clReleaseSemaphoreKHR(sema_object); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } #[cfg(feature = "cl_khr_semaphore")] pub unsafe fn retain_semaphore_khr(sema_object: cl_semaphore_khr) -> Result<(), cl_int> { let status: cl_int = clRetainSemaphoreKHR(sema_object); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -1156,10 +1156,10 @@ pub unsafe fn import_memory_arm( ) -> Result { let mut status: cl_int = CL_INVALID_VALUE; let mem: cl_mem = clImportMemoryARM(context, flags, properties, memory, size, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -1211,10 +1211,10 @@ pub unsafe fn enqueue_svm_free_arm( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1239,10 +1239,10 @@ pub unsafe fn enqueue_svm_mem_cpy_arm( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1267,10 +1267,10 @@ pub unsafe fn enqueue_svm_mem_fill_arm( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1295,10 +1295,10 @@ pub unsafe fn enqueue_svm_map_arm( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1317,10 +1317,10 @@ pub unsafe fn enqueue_svm_unmap_arm( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1331,10 +1331,10 @@ pub fn set_kernel_arg_svm_pointer( arg_ptr: *const c_void, ) -> Result<(), cl_int> { let status: cl_int = unsafe { clSetKernelArgSVMPointerARM(kernel, arg_index, arg_ptr) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -1347,10 +1347,10 @@ pub fn set_kernel_exec_info_arm( ) -> Result<(), cl_int> { let status: cl_int = unsafe { clSetKernelExecInfoARM(kernel, param_name, param_value_size, param_value) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -1371,10 +1371,10 @@ pub fn create_accelerator_intel( &mut status, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(ptr) + } else { + Err(status) } } @@ -1418,20 +1418,20 @@ pub fn get_accelerator_info_intel( #[cfg(feature = "cl_intel_accelerator")] pub unsafe fn retain_accelerator_intel(accelerator: cl_accelerator_intel) -> Result<(), cl_int> { let status = clRetainAcceleratorINTEL(accelerator); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } #[cfg(feature = "cl_intel_accelerator")] pub unsafe fn release_accelerator_intel(accelerator: cl_accelerator_intel) -> Result<(), cl_int> { let status = clReleaseAcceleratorINTEL(accelerator); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -1444,10 +1444,10 @@ pub unsafe fn host_mem_alloc_intel( ) -> Result<(), cl_int> { let mut status: cl_int = CL_INVALID_VALUE; clHostMemAllocINTEL(context, properties, size, alignment, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -1461,10 +1461,10 @@ pub unsafe fn device_mem_alloc_intel( ) -> Result<(), cl_int> { let mut status: cl_int = CL_INVALID_VALUE; clDeviceMemAllocINTEL(context, device, properties, size, alignment, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -1478,30 +1478,30 @@ pub unsafe fn shared_mem_alloc_intel( ) -> Result<(), cl_int> { let mut status: cl_int = CL_INVALID_VALUE; clSharedMemAllocINTEL(context, device, properties, size, alignment, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } #[cfg(feature = "cl_intel_unified_shared_memory")] pub unsafe fn mem_free_intel(context: cl_context, ptr: *mut c_void) -> Result<(), cl_int> { let status = clMemFreeINTEL(context, ptr); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } #[cfg(feature = "cl_intel_unified_shared_memory")] pub unsafe fn mem_blocking_free_intel(context: cl_context, ptr: *mut c_void) -> Result<(), cl_int> { let status = clMemBlockingFreeINTEL(context, ptr); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -1523,10 +1523,10 @@ fn mem_alloc_info_intel( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(data) + } else { + Err(status) } } @@ -1571,10 +1571,10 @@ pub fn get_mem_alloc_info_intel( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(InfoType::VecUchar(data)) + } else { + Err(status) } } else { Ok(InfoType::VecUchar(Vec::default())) @@ -1590,10 +1590,10 @@ pub unsafe fn set_kernel_arg_mem_pointer_intel( arg_value: *const c_void, ) -> Result<(), cl_int> { let status = clSetKernelArgMemPointerINTEL(kernel, arg_index, arg_value); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -1616,10 +1616,10 @@ pub unsafe fn enqueue_mem_set_intel( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1644,10 +1644,10 @@ pub unsafe fn enqueue_mem_fill_intel( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1672,10 +1672,10 @@ pub unsafe fn enqueue_mem_copy_intel( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1698,10 +1698,10 @@ pub unsafe fn enqueue_migrate_mem_intel( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1724,10 +1724,10 @@ pub unsafe fn enqueue_mem_advise_intel( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1742,10 +1742,10 @@ pub unsafe fn create_buffer_with_properties_intel( let mut status: cl_int = CL_INVALID_VALUE; let mem: cl_mem = clCreateBufferWithPropertiesINTEL(context, properties, flags, size, host_ptr, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -1772,10 +1772,10 @@ pub unsafe fn enqueue_read_host_pipe_intel( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1802,10 +1802,10 @@ pub unsafe fn enqueue_write_host_pipe_intel( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -1833,9 +1833,7 @@ pub fn get_image_requirements_info_ext( &mut size, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { // Get the data. let mut data: Vec = Vec::with_capacity(size); let status = unsafe { @@ -1852,11 +1850,13 @@ pub fn get_image_requirements_info_ext( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(data) + } else { + Err(status) } + } else { + Err(status) } } @@ -1865,9 +1865,7 @@ pub fn get_icd_loader_info_oclicd(param_name: cl_icdl_info) -> Result, c // get the size let mut size: size_t = 0; let status = unsafe { clGetICDLoaderInfoOCLICD(param_name, 0, ptr::null_mut(), &mut size) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { // Get the data. let mut data: Vec = Vec::with_capacity(size); let status = unsafe { @@ -1878,11 +1876,13 @@ pub fn get_icd_loader_info_oclicd(param_name: cl_icdl_info) -> Result, c ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(data) + } else { + Err(status) } + } else { + Err(status) } } @@ -1892,9 +1892,9 @@ pub fn set_content_size_buffer_pocl( content_size_buffer: cl_mem, ) -> Result<(), cl_int> { let status = unsafe { clSetContentSizeBufferPoCL(buffer, content_size_buffer) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } diff --git a/src/gl.rs b/src/gl.rs index 36bba4e..1a364a5 100644 --- a/src/gl.rs +++ b/src/gl.rs @@ -63,10 +63,10 @@ pub unsafe fn create_from_gl_buffer( ) -> Result { let mut status: cl_int = CL_INVALID_VALUE; let mem = clCreateFromGLBuffer(context, flags, bufobj, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -102,10 +102,10 @@ pub unsafe fn create_from_gl_texture( texture, &mut status, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -128,10 +128,10 @@ pub unsafe fn create_from_gl_render_buffer( ) -> Result { let mut status: cl_int = CL_INVALID_VALUE; let mem = clCreateFromGLRenderbuffer(context, flags, renderbuffer, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -147,10 +147,10 @@ pub fn get_gl_object_info(memobj: cl_mem) -> Result<(cl_GLuint, cl_GLuint), cl_i let mut object_type: cl_uint = CL_GL_OBJECT_BUFFER; let mut object_name: cl_uint = 0; let status = unsafe { clGetGLObjectInfo(memobj, &mut object_type, &mut object_name) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok((object_type, object_name)) + } else { + Err(status) } } @@ -222,10 +222,10 @@ pub unsafe fn enqueue_acquire_gl_objects( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -257,10 +257,10 @@ pub unsafe fn enqueue_release_gl_objects( event_wait_list, &mut event, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } @@ -309,10 +309,10 @@ pub unsafe fn create_from_gl_texture_2d( texture, &mut status, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -360,10 +360,10 @@ pub unsafe fn create_from_gl_texture_3d( texture, &mut status, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -394,10 +394,10 @@ pub fn get_gl_context_info_khr( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(InfoType::Ptr(data)) + } else { + Err(status) } } @@ -422,10 +422,10 @@ pub fn get_gl_context_info_khr( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(InfoType::VecIntPtr(data)) + } else { + Err(status) } } else { Ok(InfoType::VecIntPtr(Vec::default())) @@ -452,10 +452,10 @@ pub fn get_gl_context_info_khr( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(InfoType::VecUchar(data)) + } else { + Err(status) } } else { Ok(InfoType::VecUchar(Vec::default())) @@ -481,9 +481,9 @@ pub fn create_event_from_gl_sync_khr( ) -> Result { let mut status: cl_int = CL_INVALID_VALUE; let event: cl_event = unsafe { clCreateEventFromGLsyncKHR(context, sync, &mut status) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(event) + } else { + Err(status) } } diff --git a/src/kernel.rs b/src/kernel.rs index 74984c8..b4d99cc 100644 --- a/src/kernel.rs +++ b/src/kernel.rs @@ -75,10 +75,10 @@ use std::ptr; pub fn create_kernel(program: cl_program, kernel_name: &CStr) -> Result { let mut status: cl_int = CL_INVALID_VALUE; let kernel: cl_kernel = unsafe { clCreateKernel(program, kernel_name.as_ptr(), &mut status) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(kernel) + } else { + Err(status) } } @@ -86,10 +86,10 @@ fn count_kernels_in_program(program: cl_program) -> Result { let mut count: cl_uint = 0; let status: cl_int = unsafe { clCreateKernelsInProgram(program, 0, ptr::null_mut(), &mut count) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(count) + } else { + Err(status) } } @@ -113,10 +113,10 @@ pub fn create_kernels_in_program(program: cl_program) -> Result, ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(kernels) + } else { + Err(status) } } @@ -133,10 +133,10 @@ pub fn create_kernels_in_program(program: cl_program) -> Result, pub fn clone_kernel(source_kernel: cl_kernel) -> Result { let mut status: cl_int = CL_INVALID_VALUE; let kernel: cl_kernel = unsafe { clCloneKernel(source_kernel, &mut status) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(kernel) + } else { + Err(status) } } @@ -153,10 +153,10 @@ pub fn clone_kernel(source_kernel: cl_kernel) -> Result { #[inline] pub unsafe fn retain_kernel(kernel: cl_kernel) -> Result<(), cl_int> { let status: cl_int = clRetainKernel(kernel); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -173,10 +173,10 @@ pub unsafe fn retain_kernel(kernel: cl_kernel) -> Result<(), cl_int> { #[inline] pub unsafe fn release_kernel(kernel: cl_kernel) -> Result<(), cl_int> { let status: cl_int = clReleaseKernel(kernel); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -200,10 +200,10 @@ pub unsafe fn set_kernel_arg( arg_value: *const c_void, ) -> Result<(), cl_int> { let status: cl_int = clSetKernelArg(kernel, arg_index, arg_size, arg_value); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -227,10 +227,10 @@ pub unsafe fn set_kernel_arg_svm_pointer( arg_ptr: *const c_void, ) -> Result<(), cl_int> { let status: cl_int = clSetKernelArgSVMPointer(kernel, arg_index, arg_ptr); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -256,10 +256,10 @@ pub unsafe fn set_kernel_exec_info( param_value: *const c_void, ) -> Result<(), cl_int> { let status: cl_int = clSetKernelExecInfo(kernel, param_name, param_value_size, param_value); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -463,10 +463,10 @@ pub fn get_kernel_sub_group_info( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(InfoType::Size(data)) + } else { + Err(status) } } @@ -484,9 +484,7 @@ pub fn get_kernel_sub_group_info( &mut size, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { // Get the information. let count = size / mem::size_of::(); let mut data: Vec = Vec::with_capacity(count); @@ -503,11 +501,13 @@ pub fn get_kernel_sub_group_info( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(InfoType::VecSize(data)) + } else { + Err(status) } + } else { + Err(status) } } @@ -525,9 +525,7 @@ pub fn get_kernel_sub_group_info( &mut size, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { // Get the information. let count = size / mem::size_of::(); let mut data: Vec = Vec::with_capacity(count); @@ -544,11 +542,13 @@ pub fn get_kernel_sub_group_info( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(InfoType::VecUchar(data)) + } else { + Err(status) } + } else { + Err(status) } } } diff --git a/src/layer.rs b/src/layer.rs index 9d8a747..a1bcbb4 100644 --- a/src/layer.rs +++ b/src/layer.rs @@ -27,9 +27,7 @@ use std::ptr; pub fn get_layer_data(param_name: cl_layer_info) -> Result, cl_int> { let mut size: size_t = 0; let status = unsafe { clGetLayerInfo(param_name, 0, ptr::null_mut(), &mut size) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { let mut data: Vec = Vec::with_capacity(size); let status = unsafe { clGetLayerInfo( @@ -39,11 +37,13 @@ pub fn get_layer_data(param_name: cl_layer_info) -> Result, cl_int> { ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(data) + } else { + Err(status) } + } else { + Err(status) } } @@ -65,10 +65,10 @@ pub unsafe fn init_layer( &mut num_entries_ret, &mut layer_dispatch_ret, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { let slice = std::slice::from_raw_parts(layer_dispatch_ret, num_entries_ret as usize); Ok(slice) + } else { + Err(status) } } diff --git a/src/memory.rs b/src/memory.rs index 64edd5c..17f6be4 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -87,10 +87,10 @@ pub unsafe fn create_buffer( ) -> Result { let mut status: cl_int = CL_INVALID_VALUE; let mem: cl_mem = clCreateBuffer(context, flags, size, host_ptr, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -126,10 +126,10 @@ pub unsafe fn create_sub_buffer( buffer_create_info, &mut status, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -171,10 +171,10 @@ pub unsafe fn create_image( host_ptr, &mut status, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -214,10 +214,10 @@ pub unsafe fn create_pipe( ptr::null(), &mut status, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -252,10 +252,10 @@ pub unsafe fn create_buffer_with_properties( let mut status: cl_int = CL_INVALID_VALUE; let mem: cl_mem = clCreateBufferWithProperties(context, properties, flags, size, host_ptr, &mut status); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -301,10 +301,10 @@ pub unsafe fn create_image_with_properties( host_ptr, &mut status, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(mem) + } else { + Err(status) } } @@ -321,10 +321,10 @@ pub unsafe fn create_image_with_properties( #[inline] pub unsafe fn retain_mem_object(memobj: cl_mem) -> Result<(), cl_int> { let status: cl_int = clRetainMemObject(memobj); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -341,10 +341,10 @@ pub unsafe fn retain_mem_object(memobj: cl_mem) -> Result<(), cl_int> { #[inline] pub unsafe fn release_mem_object(memobj: cl_mem) -> Result<(), cl_int> { let status: cl_int = clReleaseMemObject(memobj); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -357,10 +357,10 @@ fn count_supported_image_formats( let status: cl_int = unsafe { clGetSupportedImageFormats(context, flags, image_type, 0, ptr::null_mut(), &mut count) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(count) + } else { + Err(status) } } @@ -395,10 +395,10 @@ pub fn get_supported_image_formats( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(image_formats) + } else { + Err(status) } } @@ -569,10 +569,10 @@ pub unsafe fn set_mem_object_destructor_callback( user_data: *mut c_void, ) -> Result<(), cl_int> { let status: cl_int = clSetMemObjectDestructorCallback(memobj, Some(pfn_notify), user_data); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } diff --git a/src/platform.rs b/src/platform.rs index f2707f4..7b8a735 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -63,10 +63,10 @@ pub fn get_platform_ids() -> Result, cl_int> { ids.set_len(len); }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(ids) + } else { + Err(status) } } else { Ok(Vec::default()) diff --git a/src/program.rs b/src/program.rs index de4d59e..53f5a9b 100644 --- a/src/program.rs +++ b/src/program.rs @@ -112,10 +112,10 @@ pub fn create_program_with_source( ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(program) + } else { + Err(status) } } @@ -152,10 +152,10 @@ pub unsafe fn create_program_with_binary( &mut status, ); binary_status.set_len(binaries_length); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(program) + } else { + Err(status) } } @@ -189,10 +189,10 @@ pub unsafe fn create_program_with_builtin_kernels( kernel_names.as_ptr(), &mut status, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(program) + } else { + Err(status) } } @@ -218,10 +218,10 @@ pub fn create_program_with_il(context: cl_context, il: &[u8]) -> Result Result Result<(), cl_int> { let status: cl_int = clRetainProgram(program); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -258,10 +258,10 @@ pub unsafe fn retain_program(program: cl_program) -> Result<(), cl_int> { #[inline] pub unsafe fn release_program(program: cl_program) -> Result<(), cl_int> { let status: cl_int = clReleaseProgram(program); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -295,10 +295,10 @@ pub fn build_program( user_data, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -357,10 +357,10 @@ pub fn compile_program( user_data, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -409,10 +409,10 @@ pub unsafe fn link_program( user_data, &mut status, ); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(programme) + } else { + Err(status) } } @@ -438,10 +438,10 @@ pub unsafe fn set_program_release_callback( user_data: *mut c_void, ) -> Result<(), cl_int> { let status: cl_int = clSetProgramReleaseCallback(program, pfn_notify, user_data); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -470,10 +470,10 @@ pub unsafe fn set_program_specialization_constant( ) -> Result<(), cl_int> { let status: cl_int = clSetProgramSpecializationConstant(program, spec_id, spec_size, spec_value); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -491,10 +491,10 @@ pub unsafe fn set_program_specialization_constant( #[inline] pub unsafe fn unload_platform_compiler(platform: cl_platform_id) -> Result<(), cl_int> { let status: cl_int = clUnloadPlatformCompiler(platform); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -579,10 +579,10 @@ pub fn get_program_info( ptr::null_mut(), ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(InfoType::VecVecUchar(binaries)) + } else { + Err(status) } } diff --git a/src/sampler.rs b/src/sampler.rs index 420cb7d..08cf925 100644 --- a/src/sampler.rs +++ b/src/sampler.rs @@ -78,10 +78,10 @@ pub fn create_sampler( &mut status, ) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(sampler) + } else { + Err(status) } } @@ -104,10 +104,10 @@ pub fn create_sampler_with_properties( let mut status: cl_int = CL_INVALID_VALUE; let sampler: cl_sampler = unsafe { clCreateSamplerWithProperties(context, properties, &mut status) }; - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(sampler) + } else { + Err(status) } } @@ -124,10 +124,10 @@ pub fn create_sampler_with_properties( #[inline] pub unsafe fn retain_sampler(sampler: cl_sampler) -> Result<(), cl_int> { let status: cl_int = clRetainSampler(sampler); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } } @@ -144,10 +144,10 @@ pub unsafe fn retain_sampler(sampler: cl_sampler) -> Result<(), cl_int> { #[inline] pub unsafe fn release_sampler(sampler: cl_sampler) -> Result<(), cl_int> { let status: cl_int = clReleaseSampler(sampler); - if CL_SUCCESS != status { - Err(status) - } else { + if CL_SUCCESS == status { Ok(()) + } else { + Err(status) } }