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() {
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)));
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)));
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;
#include "core/resource.hpp"
#include "pipe/p_screen.h"
#include "util/u_sampler.h"
+#include "util/u_format.h"
using namespace clover;
}
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 {};
info.depth0 = img->depth();
} else {
info.width0 = obj.size();
+ info.height0 = 1;
+ info.depth0 = 1;
}
info.target = translate_target(obj.type());
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,
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();