From fab6fa2bc8af9153a8dae84f25ebb85d1a3b1345 Mon Sep 17 00:00:00 2001 From: LingMan <18294-LingMan@users.noreply.gitlab.freedesktop.org> Date: Thu, 10 Oct 2024 01:58:22 +0200 Subject: [PATCH] rusticl/cl_prop: Use C-string literals Avoids some pointless allocations when converting `&str` to `&CStr`. Reviewed-by: Karol Herbst Part-of: --- src/gallium/frontends/rusticl/api/device.rs | 10 +++++----- src/gallium/frontends/rusticl/api/platform.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/device.rs b/src/gallium/frontends/rusticl/api/device.rs index 17f48d17c43..ba3cdf4aecf 100644 --- a/src/gallium/frontends/rusticl/api/device.rs +++ b/src/gallium/frontends/rusticl/api/device.rs @@ -16,7 +16,7 @@ use std::ffi::CStr; use std::mem::{size_of, MaybeUninit}; use std::ptr; -const SPIRV_SUPPORT_STRING: &str = "SPIR-V_1.0 SPIR-V_1.1 SPIR-V_1.2 SPIR-V_1.3 SPIR-V_1.4"; +const SPIRV_SUPPORT_STRING: &CStr = c"SPIR-V_1.0 SPIR-V_1.1 SPIR-V_1.2 SPIR-V_1.3 SPIR-V_1.4"; const SPIRV_SUPPORT: [cl_name_version; 5] = [ mk_cl_version_ext(1, 0, 0, "SPIR-V"), mk_cl_version_ext(1, 1, 0, "SPIR-V"), @@ -46,7 +46,7 @@ impl CLInfo for cl_device_id { as cl_device_atomic_capabilities, ), CL_DEVICE_AVAILABLE => cl_prop::(true), - CL_DEVICE_BUILT_IN_KERNELS => cl_prop::<&str>(""), + CL_DEVICE_BUILT_IN_KERNELS => cl_prop::<&CStr>(c""), CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION => cl_prop::>(Vec::new()), CL_DEVICE_COMPILER_AVAILABLE => cl_prop::(true), CL_DEVICE_CROSS_DEVICE_SHARED_MEM_CAPABILITIES_INTEL => { @@ -100,7 +100,7 @@ impl CLInfo for cl_device_id { cl_prop::(0) } CL_DEVICE_HOST_UNIFIED_MEMORY => cl_prop::(dev.unified_memory()), - CL_DEVICE_IL_VERSION => cl_prop::<&str>(SPIRV_SUPPORT_STRING), + CL_DEVICE_IL_VERSION => cl_prop::<&CStr>(SPIRV_SUPPORT_STRING), CL_DEVICE_ILS_WITH_VERSION => cl_prop::>(SPIRV_SUPPORT.to_vec()), CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT => { cl_prop::(dev.image_base_address_alignment()) @@ -252,9 +252,9 @@ impl CLInfo for cl_device_id { } CL_DEVICE_PRINTF_BUFFER_SIZE => cl_prop::(dev.printf_buffer_size()), CL_DEVICE_PROFILE => cl_prop(if dev.embedded { - "EMBEDDED_PROFILE" + c"EMBEDDED_PROFILE" } else { - "FULL_PROFILE" + c"FULL_PROFILE" }), CL_DEVICE_PROFILING_TIMER_RESOLUTION => { cl_prop::(dev.caps.timer_resolution as usize) diff --git a/src/gallium/frontends/rusticl/api/platform.rs b/src/gallium/frontends/rusticl/api/platform.rs index 2453fb6eedf..347abb4cf43 100644 --- a/src/gallium/frontends/rusticl/api/platform.rs +++ b/src/gallium/frontends/rusticl/api/platform.rs @@ -21,13 +21,13 @@ impl CLInfo for cl_platform_id { cl_prop::>(PLATFORM_EXTENSIONS.to_vec()) } CL_PLATFORM_HOST_TIMER_RESOLUTION => cl_prop::(1), - CL_PLATFORM_ICD_SUFFIX_KHR => cl_prop("MESA"), - CL_PLATFORM_NAME => cl_prop("rusticl"), + CL_PLATFORM_ICD_SUFFIX_KHR => cl_prop(c"MESA"), + CL_PLATFORM_NAME => cl_prop(c"rusticl"), CL_PLATFORM_NUMERIC_VERSION => cl_prop::(CLVersion::Cl3_0 as u32), - CL_PLATFORM_PROFILE => cl_prop("FULL_PROFILE"), - CL_PLATFORM_VENDOR => cl_prop("Mesa/X.org"), + CL_PLATFORM_PROFILE => cl_prop(c"FULL_PROFILE"), + CL_PLATFORM_VENDOR => cl_prop(c"Mesa/X.org"), // OpenCL - CL_PLATFORM_VERSION => cl_prop("OpenCL 3.0 "), + CL_PLATFORM_VERSION => cl_prop(c"OpenCL 3.0 "), // CL_INVALID_VALUE if param_name is not one of the supported values _ => return Err(CL_INVALID_VALUE), })