rusticl/mesa: Return CStr for device and vendor names.
This allows us to skip converting between Rust and C strings when fetching those. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30888>
This commit is contained in:
@@ -198,7 +198,7 @@ impl CLInfo<cl_device_info> for cl_device_id {
|
||||
CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE => {
|
||||
cl_prop::<cl_uint>(16 * size_of::<cl_ulong>() as cl_uint)
|
||||
}
|
||||
CL_DEVICE_NAME => cl_prop::<&str>(&dev.screen().name()),
|
||||
CL_DEVICE_NAME => cl_prop::<&CStr>(dev.screen().name()),
|
||||
CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR => cl_prop::<cl_uint>(1),
|
||||
CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE => cl_prop::<cl_uint>(dev.fp64_supported().into()),
|
||||
CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT => cl_prop::<cl_uint>(1),
|
||||
@@ -299,7 +299,7 @@ impl CLInfo<cl_device_info> for cl_device_id {
|
||||
CL_DEVICE_UUID_KHR => cl_prop::<[cl_uchar; CL_UUID_SIZE_KHR as usize]>(
|
||||
dev.screen().device_uuid().unwrap_or_default(),
|
||||
),
|
||||
CL_DEVICE_VENDOR => cl_prop::<&str>(&dev.screen().device_vendor()),
|
||||
CL_DEVICE_VENDOR => cl_prop::<&CStr>(dev.screen().device_vendor()),
|
||||
CL_DEVICE_VENDOR_ID => cl_prop::<cl_uint>(dev.vendor_id()),
|
||||
CL_DEVICE_VERSION => cl_prop::<&str>(&format!("OpenCL {} ", dev.cl_version.api_str())),
|
||||
CL_DRIVER_UUID_KHR => cl_prop::<[cl_char; CL_UUID_SIZE_KHR as usize]>(
|
||||
|
||||
@@ -357,7 +357,7 @@ impl Program {
|
||||
}
|
||||
|
||||
let name: &[u8] = slice::from_raw_parts(name.cast(), name_length);
|
||||
if dev.screen().name().as_bytes() != name {
|
||||
if dev.screen().name().to_bytes() != name {
|
||||
return Err(CL_INVALID_BINARY);
|
||||
}
|
||||
|
||||
@@ -472,7 +472,7 @@ impl Program {
|
||||
let info = lock.dev_build(d);
|
||||
|
||||
res.push(info.spirv.as_ref().map_or(0, |s| {
|
||||
s.to_bin().len() + d.screen().name().as_bytes().len() + BIN_HEADER_SIZE
|
||||
s.to_bin().len() + d.screen().name().to_bytes().len() + BIN_HEADER_SIZE
|
||||
}));
|
||||
}
|
||||
res
|
||||
@@ -519,7 +519,7 @@ impl Program {
|
||||
blob_write_uint32(&mut blob, 1_u32.to_le());
|
||||
|
||||
let device_name = d.screen().name();
|
||||
let device_name = device_name.as_bytes();
|
||||
let device_name = device_name.to_bytes();
|
||||
|
||||
blob_write_uint32(&mut blob, (device_name.len() as u32).to_le());
|
||||
blob_write_uint32(&mut blob, (spirv.len() as u32).to_le());
|
||||
|
||||
@@ -7,7 +7,6 @@ use crate::util::disk_cache::*;
|
||||
use mesa_rust_gen::*;
|
||||
use mesa_rust_util::has_required_feature;
|
||||
use mesa_rust_util::ptr::ThreadSafeCPtr;
|
||||
use mesa_rust_util::string::*;
|
||||
|
||||
use std::convert::TryInto;
|
||||
use std::ffi::CStr;
|
||||
@@ -300,8 +299,8 @@ impl PipeScreen {
|
||||
self.ldev.driver_name()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> String {
|
||||
unsafe { c_string_to_string(self.screen().get_name.unwrap()(self.screen.as_ptr())) }
|
||||
pub fn name(&self) -> &CStr {
|
||||
unsafe { CStr::from_ptr(self.screen().get_name.unwrap()(self.screen.as_ptr())) }
|
||||
}
|
||||
|
||||
pub fn device_node_mask(&self) -> Option<u32> {
|
||||
@@ -326,9 +325,9 @@ impl PipeScreen {
|
||||
Some(luid)
|
||||
}
|
||||
|
||||
pub fn device_vendor(&self) -> String {
|
||||
pub fn device_vendor(&self) -> &CStr {
|
||||
unsafe {
|
||||
c_string_to_string(self.screen().get_device_vendor.unwrap()(
|
||||
CStr::from_ptr(self.screen().get_device_vendor.unwrap()(
|
||||
self.screen.as_ptr(),
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user