From 6a18e154bce5bfca6cb195406440483a473d90e7 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Sun, 2 Oct 2022 13:54:24 +0200 Subject: [PATCH] rusticl/mem: propper CL_MEM_ALLOC_HOST_PTR support Signed-off-by: Karol Herbst Part-of: --- src/gallium/frontends/rusticl/core/context.rs | 14 ++++-------- src/gallium/frontends/rusticl/core/memory.rs | 33 +++++++++++++++++---------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/gallium/frontends/rusticl/core/context.rs b/src/gallium/frontends/rusticl/core/context.rs index e04f2b8..e38ab73 100644 --- a/src/gallium/frontends/rusticl/core/context.rs +++ b/src/gallium/frontends/rusticl/core/context.rs @@ -43,6 +43,7 @@ impl Context { size: usize, user_ptr: *mut c_void, copy: bool, + res_type: ResourceType, ) -> CLResult, Arc>> { let adj_size: u32 = size.try_into().map_err(|_| CL_OUT_OF_HOST_MEMORY)?; let mut res = HashMap::new(); @@ -56,9 +57,7 @@ impl Context { } if resource.is_none() { - resource = dev - .screen() - .resource_create_buffer(adj_size, ResourceType::Normal) + resource = dev.screen().resource_create_buffer(adj_size, res_type) } let resource = resource.ok_or(CL_OUT_OF_RESOURCES); @@ -84,6 +83,7 @@ impl Context { format: &cl_image_format, user_ptr: *mut c_void, copy: bool, + res_type: ResourceType, ) -> CLResult, Arc>> { let width = desc .image_width @@ -117,13 +117,7 @@ impl Context { if resource.is_none() { resource = dev.screen().resource_create_texture( - width, - height, - depth, - array_size, - target, - format, - ResourceType::Normal, + width, height, depth, array_size, target, format, res_type, ) } diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 44eec4c..fe7d59b 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -291,12 +291,18 @@ impl Mem { host_ptr: *mut c_void, props: Vec, ) -> CLResult> { - if bit_check(flags, CL_MEM_ALLOC_HOST_PTR) { - println!("host ptr semantics not implemented!"); - } + let res_type = if bit_check(flags, CL_MEM_ALLOC_HOST_PTR) { + ResourceType::Staging + } else { + ResourceType::Normal + }; - let buffer = - context.create_buffer(size, host_ptr, bit_check(flags, CL_MEM_COPY_HOST_PTR))?; + let buffer = context.create_buffer( + size, + host_ptr, + bit_check(flags, CL_MEM_COPY_HOST_PTR), + res_type, + )?; let host_ptr = if bit_check(flags, CL_MEM_USE_HOST_PTR) { host_ptr @@ -365,10 +371,6 @@ impl Mem { host_ptr: *mut c_void, props: Vec, ) -> CLResult> { - if bit_check(flags, CL_MEM_ALLOC_HOST_PTR) { - println!("host ptr semantics not implemented!"); - } - // we have to sanitize the image_desc a little for internal use let api_image_desc = image_desc; let dims = image_desc.dims(); @@ -383,12 +385,19 @@ impl Mem { image_desc.image_array_size = 1; } + let res_type = if bit_check(flags, CL_MEM_ALLOC_HOST_PTR) { + ResourceType::Staging + } else { + ResourceType::Normal + }; + let texture = if parent.is_none() { Some(context.create_texture( &image_desc, image_format, host_ptr, bit_check(flags, CL_MEM_COPY_HOST_PTR), + res_type, )?) } else { None @@ -458,8 +467,8 @@ impl Mem { assert!(self.is_buffer()); - // don't bother mapping directly if it's not UMA - let tx = if q.device.unified_memory() { + // don't bother mapping directly if it's not UMA or a staging buffer + let tx = if q.device.unified_memory() || bit_check(b.flags, CL_MEM_ALLOC_HOST_PTR) { ctx.buffer_map_directly( r, offset.try_into().map_err(|_| CL_OUT_OF_HOST_MEMORY)?, @@ -519,7 +528,7 @@ impl Mem { let ctx = q.device.helper_ctx(); // don't bother mapping directly if it's not UMA - let tx = if q.device.unified_memory() { + let tx = if q.device.unified_memory() || bit_check(self.flags, CL_MEM_ALLOC_HOST_PTR) { ctx.texture_map_directly(r, bx, rw) } else { None -- 2.7.4