rusticl: Replace &Arc<Device> with &Device

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24061>
This commit is contained in:
Karol Herbst 2023-07-08 17:38:02 +02:00 committed by Marge Bot
parent 5bd235189a
commit afe95b613c
5 changed files with 20 additions and 25 deletions

View file

@ -97,8 +97,8 @@ fn create_context_from_type(
check_cl_device_type(device_type)?;
let devs: Vec<_> = get_devs_for_type(device_type)
.iter()
.map(|d| cl_device_id::from_ptr(Arc::as_ptr(d)))
.into_iter()
.map(|d| cl_device_id::from_ptr(d))
.collect();
// CL_DEVICE_NOT_FOUND if no devices that match device_type and property values specified in properties were found.

View file

@ -320,10 +320,11 @@ fn devs() -> &'static Vec<Arc<Device>> {
&Platform::get().devs
}
pub fn get_devs_for_type(device_type: cl_device_type) -> Vec<&'static Arc<Device>> {
pub fn get_devs_for_type(device_type: cl_device_type) -> Vec<&'static Device> {
devs()
.iter()
.filter(|d| device_type & d.device_type(true) != 0)
.map(Arc::as_ref)
.collect()
}
@ -367,8 +368,7 @@ fn get_device_ids(
#[allow(clippy::needless_range_loop)]
for i in 0..n {
unsafe {
// Note we use as_ptr here which doesn't increase the reference count.
*devices.add(i) = cl_device_id::from_ptr(Arc::as_ptr(devs[i]));
*devices.add(i) = cl_device_id::from_ptr(devs[i]);
}
}
}

View file

@ -734,7 +734,7 @@ pub(super) fn convert_spirv_to_nir(
build: &ProgramBuild,
name: &str,
args: &[spirv::SPIRVKernelArg],
dev: &Arc<Device>,
dev: &Device,
) -> (NirShader, Vec<KernelArg>, Vec<InternalKernelArg>) {
let cache = dev.screen().shader_cache();
let key = build.hash_key(dev, name);
@ -1192,7 +1192,7 @@ impl Kernel {
&self.build.args[idx as usize].spirv.type_name
}
pub fn priv_mem_size(&self, dev: &Arc<Device>) -> cl_ulong {
pub fn priv_mem_size(&self, dev: &Device) -> cl_ulong {
self.dev_state.get(dev).info.private_memory.into()
}
@ -1204,7 +1204,7 @@ impl Kernel {
self.dev_state.get(dev).info.preferred_simd_size as usize
}
pub fn local_mem_size(&self, dev: &Arc<Device>) -> cl_ulong {
pub fn local_mem_size(&self, dev: &Device) -> cl_ulong {
// TODO include args
self.dev_state.get(dev).nir.shared_size() as cl_ulong
}

View file

@ -577,7 +577,7 @@ impl Mem {
self.get_parent().res.as_ref().ok_or(CL_OUT_OF_HOST_MEMORY)
}
pub fn get_res_of_dev(&self, dev: &Arc<Device>) -> CLResult<&Arc<PipeResource>> {
pub fn get_res_of_dev(&self, dev: &Device) -> CLResult<&Arc<PipeResource>> {
Ok(self.get_res()?.get(dev).unwrap())
}

View file

@ -83,7 +83,7 @@ pub(super) struct ProgramBuild {
}
impl ProgramBuild {
fn attribute_str(&self, kernel: &str, d: &Arc<Device>) -> String {
fn attribute_str(&self, kernel: &str, d: &Device) -> String {
let info = self.dev_build(d);
let attributes_strings = [
@ -100,7 +100,7 @@ impl ProgramBuild {
attributes_strings.join(",")
}
fn args(&self, dev: &Arc<Device>, kernel: &str) -> Vec<spirv::SPIRVKernelArg> {
fn args(&self, dev: &Device, kernel: &str) -> Vec<spirv::SPIRVKernelArg> {
self.dev_build(dev).spirv.as_ref().unwrap().args(kernel)
}
@ -171,7 +171,7 @@ impl ProgramBuild {
.collect()
}
pub fn hash_key(&self, dev: &Arc<Device>, name: &str) -> Option<cache_key> {
pub fn hash_key(&self, dev: &Device, name: &str) -> Option<cache_key> {
if let Some(cache) = dev.screen().shader_cache() {
let info = self.dev_build(dev);
assert_eq!(info.status, CL_BUILD_SUCCESS as cl_build_status);
@ -194,7 +194,7 @@ impl ProgramBuild {
}
}
pub fn to_nir(&self, kernel: &str, d: &Arc<Device>) -> NirShader {
pub fn to_nir(&self, kernel: &str, d: &Device) -> NirShader {
let mut spec_constants: Vec<_> = self
.spec_constants
.iter()
@ -417,19 +417,19 @@ impl Program {
info.kernel_builds.get(name).unwrap().clone()
}
pub fn status(&self, dev: &Arc<Device>) -> cl_build_status {
pub fn status(&self, dev: &Device) -> cl_build_status {
self.build_info().dev_build(dev).status
}
pub fn log(&self, dev: &Arc<Device>) -> String {
pub fn log(&self, dev: &Device) -> String {
self.build_info().dev_build(dev).log.clone()
}
pub fn bin_type(&self, dev: &Arc<Device>) -> cl_program_binary_type {
pub fn bin_type(&self, dev: &Device) -> cl_program_binary_type {
self.build_info().dev_build(dev).bin_type
}
pub fn options(&self, dev: &Arc<Device>) -> String {
pub fn options(&self, dev: &Device) -> String {
self.build_info().dev_build(dev).options.clone()
}
@ -514,7 +514,7 @@ impl Program {
.any(|b| Arc::strong_count(b) > 1)
}
pub fn build(&self, dev: &Arc<Device>, options: String) -> bool {
pub fn build(&self, dev: &Device, options: String) -> bool {
let lib = options.contains("-create-library");
let mut info = self.build_info();
if !self.do_compile(dev, options, &Vec::new(), &mut info) {
@ -557,7 +557,7 @@ impl Program {
fn do_compile(
&self,
dev: &Arc<Device>,
dev: &Device,
options: String,
headers: &[spirv::CLCHeader],
info: &mut MutexGuard<ProgramBuild>,
@ -619,12 +619,7 @@ impl Program {
}
}
pub fn compile(
&self,
dev: &Arc<Device>,
options: String,
headers: &[spirv::CLCHeader],
) -> bool {
pub fn compile(&self, dev: &Device, options: String, headers: &[spirv::CLCHeader]) -> bool {
self.do_compile(dev, options, headers, &mut self.build_info())
}