diff options
author | Francisco Jerez <[email protected]> | 2012-05-04 15:02:21 +0200 |
---|---|---|
committer | Francisco Jerez <[email protected]> | 2012-05-11 12:39:44 +0200 |
commit | 60e7b08101295099618a3c1f879440b257265253 (patch) | |
tree | c4d4f44cf49cf5b72ff91c4090d2590f8d7ca5e5 /src/gallium/state_trackers | |
parent | 19eae45e012d917b682758abeaf4fb7074c00839 (diff) |
clover: Implement CL_MEM_COPY_HOST_PTR.
Diffstat (limited to 'src/gallium/state_trackers')
4 files changed, 20 insertions, 7 deletions
diff --git a/src/gallium/state_trackers/clover/core/memory.cpp b/src/gallium/state_trackers/clover/core/memory.cpp index 1bf12e3c36e..8d8be2e547d 100644 --- a/src/gallium/state_trackers/clover/core/memory.cpp +++ b/src/gallium/state_trackers/clover/core/memory.cpp @@ -29,8 +29,9 @@ _cl_mem::_cl_mem(clover::context &ctx, cl_mem_flags flags, size_t size, void *host_ptr) : ctx(ctx), __flags(flags), __size(size), __host_ptr(host_ptr), - __destroy_notify([]{}), - data((char *)host_ptr, (host_ptr ? size : 0)) { + __destroy_notify([]{}) { + if (flags & CL_MEM_COPY_HOST_PTR) + data.append((char *)host_ptr, size); } _cl_mem::~_cl_mem() { @@ -78,7 +79,7 @@ root_buffer::resource(cl_command_queue q) { if (!resources.count(&q->dev)) { auto r = (!resources.empty() ? new root_resource(q->dev, *this, *resources.begin()->second) : - new root_resource(q->dev, *this, data)); + new root_resource(q->dev, *this, *q, data)); resources.insert(std::make_pair(&q->dev, std::unique_ptr<root_resource>(r))); @@ -129,7 +130,7 @@ image::resource(cl_command_queue q) { if (!resources.count(&q->dev)) { auto r = (!resources.empty() ? new root_resource(q->dev, *this, *resources.begin()->second) : - new root_resource(q->dev, *this, data)); + new root_resource(q->dev, *this, *q, data)); resources.insert(std::make_pair(&q->dev, std::unique_ptr<root_resource>(r))); diff --git a/src/gallium/state_trackers/clover/core/queue.hpp b/src/gallium/state_trackers/clover/core/queue.hpp index 54c949b203f..6c124eae83f 100644 --- a/src/gallium/state_trackers/clover/core/queue.hpp +++ b/src/gallium/state_trackers/clover/core/queue.hpp @@ -51,6 +51,7 @@ public: clover::device &dev; friend class clover::resource; + friend class clover::root_resource; friend class clover::mapping; friend class clover::hard_event; friend struct _cl_sampler; diff --git a/src/gallium/state_trackers/clover/core/resource.cpp b/src/gallium/state_trackers/clover/core/resource.cpp index 1d241e595aa..61085b2cb29 100644 --- a/src/gallium/state_trackers/clover/core/resource.cpp +++ b/src/gallium/state_trackers/clover/core/resource.cpp @@ -23,6 +23,7 @@ #include "core/resource.hpp" #include "pipe/p_screen.h" #include "util/u_sampler.h" +#include "util/u_format.h" using namespace clover; @@ -114,7 +115,8 @@ resource::unbind_surface(clover::command_queue &q, pipe_surface *st) { } root_resource::root_resource(clover::device &dev, clover::memory_obj &obj, - std::string data) : + clover::command_queue &q, + const std::string &data) : resource(dev, obj) { pipe_resource info {}; @@ -125,6 +127,8 @@ root_resource::root_resource(clover::device &dev, clover::memory_obj &obj, info.depth0 = img->depth(); } else { info.width0 = obj.size(); + info.height0 = 1; + info.depth0 = 1; } info.target = translate_target(obj.type()); @@ -138,7 +142,14 @@ root_resource::root_resource(clover::device &dev, clover::memory_obj &obj, if (!pipe) throw error(CL_OUT_OF_RESOURCES); - assert(data.empty()); // XXX -- initialize it with the supplied data + if (!data.empty()) { + 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, + cpp * info.width0 * info.height0); + } } root_resource::root_resource(clover::device &dev, clover::memory_obj &obj, diff --git a/src/gallium/state_trackers/clover/core/resource.hpp b/src/gallium/state_trackers/clover/core/resource.hpp index d4992972903..947060139ec 100644 --- a/src/gallium/state_trackers/clover/core/resource.hpp +++ b/src/gallium/state_trackers/clover/core/resource.hpp @@ -83,7 +83,7 @@ namespace clover { class root_resource : public resource { public: root_resource(clover::device &dev, clover::memory_obj &obj, - std::string data); + clover::command_queue &q, const std::string &data); root_resource(clover::device &dev, clover::memory_obj &obj, root_resource &r); virtual ~root_resource(); |