rusticl: Drop include paths for size_of, size_of_val, and align_of
They have been added to the prelude with Rust 1.80. Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com> Reviewed-by: Karol Herbst <kherbst@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36526>
This commit is contained in:
@@ -14,7 +14,6 @@ use rusticl_proc_macros::cl_info_entrypoint;
|
||||
use std::cmp::min;
|
||||
use std::ffi::c_char;
|
||||
use std::ffi::CStr;
|
||||
use std::mem::size_of;
|
||||
use std::ptr;
|
||||
|
||||
const SPIRV_SUPPORT_STRING: &CStr =
|
||||
|
||||
@@ -31,7 +31,7 @@ const CL_ICD2_TAG_KHR: isize = 0x434C3331;
|
||||
const CL_ICD2_TAG_KHR: isize = 0x4F50454E434C3331;
|
||||
|
||||
const fn cl_icd_dispatch_default() -> cl_icd_dispatch {
|
||||
const ELEMS: usize = mem::size_of::<cl_icd_dispatch>() / mem::size_of::<Option<fn()>>();
|
||||
const ELEMS: usize = size_of::<cl_icd_dispatch>() / size_of::<Option<fn()>>();
|
||||
|
||||
// SAFETY: cl_icd_dispatch is a list of function pointers and we set them all to None
|
||||
unsafe { mem::transmute([None::<fn()>; ELEMS]) }
|
||||
|
||||
@@ -16,7 +16,6 @@ use rusticl_proc_macros::cl_info_entrypoint;
|
||||
|
||||
use std::cmp;
|
||||
use std::ffi::CStr;
|
||||
use std::mem;
|
||||
use std::os::raw::c_void;
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
@@ -164,7 +163,7 @@ unsafe impl CLInfoObj<cl_kernel_sub_group_info, (cl_device_id, usize, *const c_v
|
||||
return Err(CL_INVALID_OPERATION);
|
||||
}
|
||||
|
||||
let usize_byte = mem::size_of::<usize>();
|
||||
let usize_byte = size_of::<usize>();
|
||||
// first we have to convert the input to a proper thing
|
||||
let input: &[usize] = match q {
|
||||
CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE | CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE => {
|
||||
@@ -382,13 +381,13 @@ fn set_kernel_arg(
|
||||
| KernelArgType::Image
|
||||
| KernelArgType::RWImage
|
||||
| KernelArgType::Texture => {
|
||||
if arg_size != std::mem::size_of::<cl_mem>() {
|
||||
if arg_size != size_of::<cl_mem>() {
|
||||
return Err(CL_INVALID_ARG_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
KernelArgType::Sampler => {
|
||||
if arg_size != std::mem::size_of::<cl_sampler>() {
|
||||
if arg_size != size_of::<cl_sampler>() {
|
||||
return Err(CL_INVALID_ARG_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ use rusticl_proc_macros::cl_info_entrypoint;
|
||||
|
||||
use std::cmp;
|
||||
use std::cmp::Ordering;
|
||||
use std::mem;
|
||||
use std::num::NonZeroU64;
|
||||
use std::os::raw::c_void;
|
||||
use std::ptr;
|
||||
@@ -2379,7 +2378,7 @@ pub fn svm_alloc(
|
||||
// When alignment is 0, the size of the largest supported type is used.
|
||||
// In the case of the full profile, that's `long16`.
|
||||
let alignment = NonZeroU64::new(alignment.into())
|
||||
.unwrap_or(NonZeroU64::new(mem::size_of::<[u64; 16]>() as u64).unwrap());
|
||||
.unwrap_or(NonZeroU64::new(size_of::<[u64; 16]>() as u64).unwrap());
|
||||
|
||||
// size is 0 or > CL_DEVICE_MAX_MEM_ALLOC_SIZE value for any device in context.
|
||||
let size = NonZeroU64::new(size as u64).ok_or(CL_INVALID_VALUE)?;
|
||||
@@ -2677,8 +2676,8 @@ fn enqueue_svm_mem_fill_impl(
|
||||
struct Pattern([u8; $bytesize]);
|
||||
|
||||
// Just to make sure the compiler didn't generate anything weird.
|
||||
static_assert!($bytesize == mem::size_of::<Pattern>());
|
||||
static_assert!($bytesize == mem::align_of::<Pattern>());
|
||||
static_assert!($bytesize == size_of::<Pattern>());
|
||||
static_assert!($bytesize == align_of::<Pattern>());
|
||||
|
||||
// CAST: We don't know exactly which type `pattern` points to, but we know it's an
|
||||
// Application Scalar Data Type (cl_char, cl_ulong, etc.) or an Application Vector Data
|
||||
|
||||
@@ -6,13 +6,13 @@ use crate::core::queue::*;
|
||||
use mesa_rust_util::properties::Properties;
|
||||
use rusticl_opencl_gen::*;
|
||||
|
||||
use std::cmp;
|
||||
use std::convert::TryInto;
|
||||
use std::ffi::{c_void, CStr};
|
||||
use std::iter::zip;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::ops::BitAnd;
|
||||
use std::sync::Arc;
|
||||
use std::{cmp, mem};
|
||||
|
||||
// TODO: use MaybeUninit::copy_from_slice once stable
|
||||
pub fn maybe_uninit_copy_from_slice<T>(this: &mut [MaybeUninit<T>], src: &[T])
|
||||
@@ -81,7 +81,7 @@ impl CLInfoValue<'_> {
|
||||
/// Used to read from the application provided data.
|
||||
pub fn input<T>(&self) -> CLResult<&[MaybeUninit<T>]> {
|
||||
if let Some(param_value) = &self.param_value {
|
||||
let count = param_value.len() / mem::size_of::<T>();
|
||||
let count = param_value.len() / size_of::<T>();
|
||||
unsafe { cl_slice::from_raw_parts(param_value.as_ptr().cast(), count) }
|
||||
} else {
|
||||
Ok(&[])
|
||||
@@ -106,7 +106,7 @@ impl CLInfoValue<'_> {
|
||||
/// All types implementing [CLProp] are supported.
|
||||
pub fn write<T: CLProp>(self, t: T) -> CLResult<CLInfoRes> {
|
||||
let count = t.count();
|
||||
let bytes = count * mem::size_of::<T::Output>();
|
||||
let bytes = count * size_of::<T::Output>();
|
||||
|
||||
// param_value is a pointer to memory where the appropriate result being queried is
|
||||
// returned. If param_value is NULL, it is ignored.
|
||||
@@ -143,7 +143,7 @@ impl CLInfoValue<'_> {
|
||||
/// `CL_PROGRAM_BINARIES`. In that case it's meaningless to write back the same pointers. This
|
||||
/// function can be used to skip those writes.
|
||||
pub fn write_len_only<T: CLProp>(self, len: usize) -> CLResult<CLInfoRes> {
|
||||
let bytes = len * mem::size_of::<T::Output>();
|
||||
let bytes = len * size_of::<T::Output>();
|
||||
|
||||
// param_value_size_ret returns the actual size in bytes of data being queried by
|
||||
// param_name. If param_value_size_ret is NULL, it is ignored.
|
||||
@@ -166,7 +166,7 @@ impl CLInfoValue<'_> {
|
||||
iter: impl ExactSizeIterator<Item = T>,
|
||||
) -> CLResult<CLInfoRes> {
|
||||
let count = iter.len();
|
||||
let bytes = count * mem::size_of::<T::Output>();
|
||||
let bytes = count * size_of::<T::Output>();
|
||||
|
||||
// param_value is a pointer to memory where the appropriate result being queried is
|
||||
// returned. If param_value is NULL, it is ignored.
|
||||
@@ -554,14 +554,13 @@ pub mod cl_slice {
|
||||
use mesa_rust_util::ptr::addr;
|
||||
use rusticl_opencl_gen::CL_INVALID_VALUE;
|
||||
use std::ffi::c_void;
|
||||
use std::mem;
|
||||
use std::slice;
|
||||
|
||||
/// Wrapper around [`std::slice::from_raw_parts`] that returns `Err(CL_INVALID_VALUE)` if any of these conditions is met:
|
||||
/// - `data` is null
|
||||
/// - `data` is not correctly aligned for `T`
|
||||
/// - `len * std::mem::size_of::<T>()` is larger than `isize::MAX`
|
||||
/// - `data` + `len * std::mem::size_of::<T>()` wraps around the address space
|
||||
/// - `len * size_of::<T>()` is larger than `isize::MAX`
|
||||
/// - `data` + `len * size_of::<T>()` wraps around the address space
|
||||
///
|
||||
/// # Safety
|
||||
/// The behavior is undefined if any of the other requirements imposed by
|
||||
@@ -587,7 +586,7 @@ pub mod cl_slice {
|
||||
data: *const c_void,
|
||||
len: usize,
|
||||
) -> CLResult<&'a [T]> {
|
||||
let size = mem::size_of::<T>();
|
||||
let size = size_of::<T>();
|
||||
if len % size != 0 {
|
||||
return Err(CL_INVALID_VALUE);
|
||||
}
|
||||
@@ -599,8 +598,8 @@ pub mod cl_slice {
|
||||
/// Wrapper around [`std::slice::from_raw_parts_mut`] that returns `Err(CL_INVALID_VALUE)` if any of these conditions is met:
|
||||
/// - `data` is null
|
||||
/// - `data` is not correctly aligned for `T`
|
||||
/// - `len * std::mem::size_of::<T>()` is larger than `isize::MAX`
|
||||
/// - `data` + `len * std::mem::size_of::<T>()` wraps around the address space
|
||||
/// - `len * size_of::<T>()` is larger than `isize::MAX`
|
||||
/// - `data` + `len * size_of::<T>()` wraps around the address space
|
||||
///
|
||||
/// # Safety
|
||||
/// The behavior is undefined if any of the other requirements imposed by
|
||||
@@ -621,7 +620,7 @@ pub mod cl_slice {
|
||||
|
||||
#[must_use]
|
||||
fn allocation_obviously_invalid<T>(data: *const T, len: usize) -> bool {
|
||||
let Some(total_size) = mem::size_of::<T>().checked_mul(len) else {
|
||||
let Some(total_size) = size_of::<T>().checked_mul(len) else {
|
||||
return true;
|
||||
};
|
||||
data.is_null()
|
||||
|
||||
@@ -512,7 +512,7 @@ impl Context {
|
||||
ctx.clear_buffer(res, &pattern, offset as u32, size as u32);
|
||||
} else {
|
||||
let slice = unsafe {
|
||||
slice::from_raw_parts_mut(svm_ptr as *mut _, size / mem::size_of_val(&pattern))
|
||||
slice::from_raw_parts_mut(svm_ptr as *mut _, size / size_of_val(&pattern))
|
||||
};
|
||||
|
||||
slice.fill(pattern);
|
||||
|
||||
@@ -32,7 +32,6 @@ use std::convert::TryInto;
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
use std::mem;
|
||||
use std::mem::size_of;
|
||||
use std::num::NonZeroU64;
|
||||
use std::ops::Deref;
|
||||
use std::os::raw::c_void;
|
||||
|
||||
@@ -16,7 +16,6 @@ use rusticl_opencl_gen::*;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::ffi::CString;
|
||||
use std::mem::size_of;
|
||||
use std::ptr::addr_of;
|
||||
use std::slice;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -8,7 +8,6 @@ use mesa_rust_gen::pipe_fd_type::*;
|
||||
use mesa_rust_gen::*;
|
||||
use mesa_rust_util::has_required_feature;
|
||||
|
||||
use std::mem::size_of;
|
||||
use std::os::raw::*;
|
||||
use std::ptr;
|
||||
use std::ptr::*;
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
/// T must not contain any uninitialized bytes such as padding.
|
||||
#[inline]
|
||||
pub unsafe fn as_byte_slice<T>(t: &[T]) -> &[u8] {
|
||||
let new_len = core::mem::size_of_val(t) / core::mem::size_of::<u8>();
|
||||
let new_len = size_of_val(t) / size_of::<u8>();
|
||||
unsafe { core::slice::from_raw_parts(t.as_ptr().cast(), new_len) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user