clover: Implement CL_MEM_COPY_HOST_PTR.
authorFrancisco Jerez <currojerez@riseup.net>
Fri, 4 May 2012 13:02:21 +0000 (15:02 +0200)
committerFrancisco Jerez <currojerez@riseup.net>
Fri, 11 May 2012 10:39:44 +0000 (12:39 +0200)
src/gallium/state_trackers/clover/core/memory.cpp
src/gallium/state_trackers/clover/core/queue.hpp
src/gallium/state_trackers/clover/core/resource.cpp
src/gallium/state_trackers/clover/core/resource.hpp

index 1bf12e3c36ec3864b1a87114319be0a439d72a00..8d8be2e547d97ff4c3c71129839c4c1480aed33e 100644 (file)
@@ -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)));
index 54c949b203faca8f03e7e6d66ff5c0f361cdcd6e..6c124eae83fe87f5ca4b862e7eec608e254f456f 100644 (file)
@@ -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;
index 1d241e595aa4a64d1257654312ca52e3ba338d03..61085b2cb294b1f3796d96d26a7b7c43ccc5c98b 100644 (file)
@@ -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,
index d4992972903da1bc9b88b8d49cc89e3d2b46d409..947060139ec8004824ec2d07a75853a6d29b5b9a 100644 (file)
@@ -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();