diff --git a/src/gallium/frontends/rusticl/api/icd.rs b/src/gallium/frontends/rusticl/api/icd.rs index 5744c0e2167..6eebb025d71 100644 --- a/src/gallium/frontends/rusticl/api/icd.rs +++ b/src/gallium/frontends/rusticl/api/icd.rs @@ -1677,30 +1677,39 @@ extern "C" fn cl_set_program_specialization_constant( } extern "C" fn cl_create_buffer_with_properties( - _context: cl_context, - _properties: *const cl_mem_properties, - _flags: cl_mem_flags, - _size: usize, - _host_ptr: *mut ::std::os::raw::c_void, + context: cl_context, + properties: *const cl_mem_properties, + flags: cl_mem_flags, + size: usize, + host_ptr: *mut ::std::os::raw::c_void, errcode_ret: *mut cl_int, ) -> cl_mem { - println!("cl_create_buffer_with_properties not implemented"); - errcode_ret.write_checked(CL_OUT_OF_HOST_MEMORY); - ptr::null_mut() + match_obj!( + create_buffer_with_properties(context, properties, flags, size, host_ptr), + errcode_ret + ) } extern "C" fn cl_create_image_with_properties( - _context: cl_context, - _properties: *const cl_mem_properties, - _flags: cl_mem_flags, - _image_format: *const cl_image_format, - _image_desc: *const cl_image_desc, - _host_ptr: *mut ::std::os::raw::c_void, + context: cl_context, + properties: *const cl_mem_properties, + flags: cl_mem_flags, + image_format: *const cl_image_format, + image_desc: *const cl_image_desc, + host_ptr: *mut ::std::os::raw::c_void, errcode_ret: *mut cl_int, ) -> cl_mem { - println!("cl_create_image_with_properties not implemented"); - errcode_ret.write_checked(CL_OUT_OF_HOST_MEMORY); - ptr::null_mut() + match_obj!( + create_image_with_properties( + context, + properties, + flags, + image_format, + image_desc, + host_ptr + ), + errcode_ret + ) } extern "C" fn cl_set_context_destructor_callback( diff --git a/src/gallium/frontends/rusticl/api/memory.rs b/src/gallium/frontends/rusticl/api/memory.rs index 93b2d5a4801..4b7372ca012 100644 --- a/src/gallium/frontends/rusticl/api/memory.rs +++ b/src/gallium/frontends/rusticl/api/memory.rs @@ -11,6 +11,7 @@ use crate::core::device::*; use crate::core::memory::*; use crate::*; +use self::mesa_rust_util::properties::Properties; use self::mesa_rust_util::ptr::*; use self::rusticl_opencl_gen::*; @@ -192,6 +193,7 @@ impl CLInfo for cl_mem { CL_MEM_MAP_COUNT => cl_prop::(0), CL_MEM_HOST_PTR => cl_prop::<*mut c_void>(mem.host_ptr), CL_MEM_OFFSET => cl_prop::(mem.offset), + CL_MEM_PROPERTIES => cl_prop::<&Vec>(&mem.props), CL_MEM_REFERENCE_COUNT => cl_prop::(self.refcnt()?), CL_MEM_SIZE => cl_prop::(mem.size), CL_MEM_TYPE => cl_prop::(mem.mem_type), @@ -201,8 +203,9 @@ impl CLInfo for cl_mem { } } -pub fn create_buffer( +pub fn create_buffer_with_properties( context: cl_context, + properties: *const cl_mem_properties, flags: cl_mem_flags, size: usize, host_ptr: *mut ::std::os::raw::c_void, @@ -226,7 +229,27 @@ pub fn create_buffer( validate_host_ptr(host_ptr, flags)?; - Ok(cl_mem::from_arc(Mem::new_buffer(c, flags, size, host_ptr)?)) + let props = Properties::from_ptr_raw(properties); + // CL_INVALID_PROPERTY if a property name in properties is not a supported property name, if + // the value specified for a supported property name is not valid, or if the same property name + // is specified more than once. + if props.len() > 1 { + // we don't support any properties besides the 0 property + return Err(CL_INVALID_PROPERTY); + } + + Ok(cl_mem::from_arc(Mem::new_buffer( + c, flags, size, host_ptr, props, + )?)) +} + +pub fn create_buffer( + context: cl_context, + flags: cl_mem_flags, + size: usize, + host_ptr: *mut ::std::os::raw::c_void, +) -> CLResult { + create_buffer_with_properties(context, ptr::null(), flags, size, host_ptr) } pub fn create_sub_buffer( @@ -649,8 +672,9 @@ impl CLInfo for cl_mem { } } -pub fn create_image( +pub fn create_image_with_properties( context: cl_context, + properties: *const cl_mem_properties, mut flags: cl_mem_flags, image_format: *const cl_image_format, image_desc: *const cl_image_desc, @@ -687,6 +711,15 @@ pub fn create_image( .find(|f| *f & filtered_flags == filtered_flags) .ok_or(CL_IMAGE_FORMAT_NOT_SUPPORTED)?; + let props = Properties::from_ptr_raw(properties); + // CL_INVALID_PROPERTY if a property name in properties is not a supported property name, if + // the value specified for a supported property name is not valid, or if the same property name + // is specified more than once. + if props.len() > 1 { + // we don't support any properties besides the 0 property + return Err(CL_INVALID_PROPERTY); + } + Ok(cl_mem::from_arc(Mem::new_image( c, desc.image_type, @@ -695,9 +728,27 @@ pub fn create_image( desc, elem_size, host_ptr, + props, ))) } +pub fn create_image( + context: cl_context, + flags: cl_mem_flags, + image_format: *const cl_image_format, + image_desc: *const cl_image_desc, + host_ptr: *mut ::std::os::raw::c_void, +) -> CLResult { + create_image_with_properties( + context, + ptr::null(), + flags, + image_format, + image_desc, + host_ptr, + ) +} + pub fn get_supported_image_formats( context: cl_context, flags: cl_mem_flags, diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 2536bba93a3..49be63e005b 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -35,6 +35,7 @@ pub struct Mem { pub image_format: cl_image_format, pub image_desc: cl_image_desc, pub image_elem_size: u8, + pub props: Vec, pub cbs: Mutex>>, res: Option, Arc>>, maps: Mutex>, @@ -72,6 +73,7 @@ impl Mem { flags: cl_mem_flags, size: usize, host_ptr: *mut c_void, + props: Vec, ) -> CLResult> { if bit_check(flags, CL_MEM_ALLOC_HOST_PTR) { println!("host ptr semantics not implemented!"); @@ -108,6 +110,7 @@ impl Mem { image_format: cl_image_format::default(), image_desc: cl_image_desc::default(), image_elem_size: 0, + props: props, cbs: Mutex::new(Vec::new()), res: Some(buffer), maps: Mutex::new(HashMap::new()), @@ -138,6 +141,7 @@ impl Mem { image_format: cl_image_format::default(), image_desc: cl_image_desc::default(), image_elem_size: 0, + props: Vec::new(), cbs: Mutex::new(Vec::new()), res: None, maps: Mutex::new(HashMap::new()), @@ -152,6 +156,7 @@ impl Mem { image_desc: cl_image_desc, image_elem_size: u8, host_ptr: *mut c_void, + props: Vec, ) -> Arc { if bit_check( flags, @@ -178,6 +183,7 @@ impl Mem { image_format: *image_format, image_desc: image_desc, image_elem_size: image_elem_size, + props: props, cbs: Mutex::new(Vec::new()), res: None, maps: Mutex::new(HashMap::new()),