summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gallium/state_trackers/clover/core/memory.cpp2
-rw-r--r--src/gallium/state_trackers/clover/core/resource.cpp17
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);
}
}