mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 19:30:11 +01:00
rusticl/mem implement the memory *WithProperties API
Signed-off-by: Karol Herbst <kherbst@redhat.com> Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15439>
This commit is contained in:
parent
4780966bf9
commit
8e13e90b71
3 changed files with 86 additions and 20 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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<cl_mem_info> for cl_mem {
|
|||
CL_MEM_MAP_COUNT => cl_prop::<cl_uint>(0),
|
||||
CL_MEM_HOST_PTR => cl_prop::<*mut c_void>(mem.host_ptr),
|
||||
CL_MEM_OFFSET => cl_prop::<usize>(mem.offset),
|
||||
CL_MEM_PROPERTIES => cl_prop::<&Vec<cl_mem_properties>>(&mem.props),
|
||||
CL_MEM_REFERENCE_COUNT => cl_prop::<cl_uint>(self.refcnt()?),
|
||||
CL_MEM_SIZE => cl_prop::<usize>(mem.size),
|
||||
CL_MEM_TYPE => cl_prop::<cl_mem_object_type>(mem.mem_type),
|
||||
|
|
@ -201,8 +203,9 @@ impl CLInfo<cl_mem_info> 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<cl_mem> {
|
||||
create_buffer_with_properties(context, ptr::null(), flags, size, host_ptr)
|
||||
}
|
||||
|
||||
pub fn create_sub_buffer(
|
||||
|
|
@ -649,8 +672,9 @@ impl CLInfo<cl_image_info> 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<cl_mem> {
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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<cl_mem_properties>,
|
||||
pub cbs: Mutex<Vec<Box<dyn Fn(cl_mem)>>>,
|
||||
res: Option<HashMap<Arc<Device>, Arc<PipeResource>>>,
|
||||
maps: Mutex<HashMap<*mut c_void, (u32, PipeTransfer)>>,
|
||||
|
|
@ -72,6 +73,7 @@ impl Mem {
|
|||
flags: cl_mem_flags,
|
||||
size: usize,
|
||||
host_ptr: *mut c_void,
|
||||
props: Vec<cl_mem_properties>,
|
||||
) -> CLResult<Arc<Mem>> {
|
||||
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<cl_mem_properties>,
|
||||
) -> Arc<Mem> {
|
||||
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()),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue