diff options
author | Grigori Goronzy <[email protected]> | 2015-05-19 09:28:30 +0200 |
---|---|---|
committer | Grigori Goronzy <[email protected]> | 2015-05-24 01:14:49 +0200 |
commit | f972b223c4cb4ec58a9451cbac5d120ac9deb336 (patch) | |
tree | 997d133fdfc43c5a9abe62b3ceb34886b727b2a5 /src/gallium | |
parent | 5c495e86388b55af067677e8608eb124a5d70d29 (diff) |
clover: try userptr for CL_MEM_USE_HOST_PTR
According to spec, CL_MEM_USE_HOST_PTR should directly use host memory,
if possible. This is just what userptr is for, so use it.
In case the memory cannot be mapped, a fallback similar to
CL_MEM_COPY_HOST_PTR is used.
v2: constify, drop unneeded cast
Reviewed-by: Francisco Jerez <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/state_trackers/clover/core/memory.cpp | 2 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/core/resource.cpp | 17 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/gallium/state_trackers/clover/core/memory.cpp b/src/gallium/state_trackers/clover/core/memory.cpp index 905ebc0fd02..055336a3325 100644 --- a/src/gallium/state_trackers/clover/core/memory.cpp +++ b/src/gallium/state_trackers/clover/core/memory.cpp @@ -30,7 +30,7 @@ memory_obj::memory_obj(clover::context &ctx, cl_mem_flags flags, size_t size, void *host_ptr) : context(ctx), _flags(flags), _size(size), _host_ptr(host_ptr) { - if (flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) + if (flags & CL_MEM_COPY_HOST_PTR) data.append((char *)host_ptr, size); } diff --git a/src/gallium/state_trackers/clover/core/resource.cpp b/src/gallium/state_trackers/clover/core/resource.cpp index 8ed4c4284e1..78ebafb644f 100644 --- a/src/gallium/state_trackers/clover/core/resource.cpp +++ b/src/gallium/state_trackers/clover/core/resource.cpp @@ -118,6 +118,8 @@ root_resource::root_resource(clover::device &dev, memory_obj &obj, command_queue &q, const std::string &data) : resource(dev, obj) { pipe_resource info {}; + const bool user_ptr_support = dev.pipe->get_param(dev.pipe, + PIPE_CAP_RESOURCE_FROM_USER_MEMORY); if (image *img = dynamic_cast<image *>(&obj)) { info.format = translate_format(img->format()); @@ -137,7 +139,15 @@ root_resource::root_resource(clover::device &dev, memory_obj &obj, PIPE_BIND_TRANSFER_READ | PIPE_BIND_TRANSFER_WRITE); - if (obj.flags() & CL_MEM_ALLOC_HOST_PTR) { + if (obj.flags() & CL_MEM_USE_HOST_PTR && user_ptr_support) { + // Page alignment is normally required for this, just try, hope for the + // best and fall back if it fails. + pipe = dev.pipe->resource_from_user_memory(dev.pipe, &info, obj.host_ptr()); + if (pipe) + return; + } + + if (obj.flags() & (CL_MEM_ALLOC_HOST_PTR | CL_MEM_USE_HOST_PTR)) { info.usage = PIPE_USAGE_STAGING; } @@ -145,12 +155,13 @@ root_resource::root_resource(clover::device &dev, memory_obj &obj, if (!pipe) throw error(CL_OUT_OF_RESOURCES); - if (!data.empty()) { + if (obj.flags() & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) { + const void *data_ptr = !data.empty() ? data.data() : obj.host_ptr(); box rect { {{ 0, 0, 0 }}, {{ info.width0, info.height0, info.depth0 }} }; unsigned cpp = util_format_get_blocksize(info.format); q.pipe->transfer_inline_write(q.pipe, pipe, 0, PIPE_TRANSFER_WRITE, - rect, data.data(), cpp * info.width0, + rect, data_ptr, cpp * info.width0, cpp * info.width0 * info.height0); } } |