diff options
author | Francisco Jerez <[email protected]> | 2013-10-01 12:00:51 -0700 |
---|---|---|
committer | Francisco Jerez <[email protected]> | 2013-10-21 10:47:03 -0700 |
commit | d6f7afc3ed41a94175a0fdf9cf9651750104974c (patch) | |
tree | eb5f57b0e2bff47f73cafde4d1e5597aebb70487 /src/gallium/state_trackers/clover/api | |
parent | 35307f540fedf9680ce8b05d0784c5b0d5b0f6a7 (diff) |
clover: Switch memory objects to the new model.
Tested-by: Tom Stellard <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/clover/api')
-rw-r--r-- | src/gallium/state_trackers/clover/api/memory.cpp | 144 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/api/transfer.cpp | 234 |
2 files changed, 179 insertions, 199 deletions
diff --git a/src/gallium/state_trackers/clover/api/memory.cpp b/src/gallium/state_trackers/clover/api/memory.cpp index b6b82f8d425..b01a1bc5bd1 100644 --- a/src/gallium/state_trackers/clover/api/memory.cpp +++ b/src/gallium/state_trackers/clover/api/memory.cpp @@ -27,10 +27,9 @@ using namespace clover; PUBLIC cl_mem -clCreateBuffer(cl_context ctx, cl_mem_flags flags, size_t size, - void *host_ptr, cl_int *errcode_ret) try { - if (!ctx) - throw error(CL_INVALID_CONTEXT); +clCreateBuffer(cl_context d_ctx, cl_mem_flags flags, size_t size, + void *host_ptr, cl_int *r_errcode) try { + auto &ctx = obj(d_ctx); if (bool(host_ptr) != bool(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) @@ -44,49 +43,47 @@ clCreateBuffer(cl_context ctx, cl_mem_flags flags, size_t size, CL_MEM_COPY_HOST_PTR)) throw error(CL_INVALID_VALUE); - ret_error(errcode_ret, CL_SUCCESS); - return new root_buffer(obj(ctx), flags, size, host_ptr); + ret_error(r_errcode, CL_SUCCESS); + return new root_buffer(ctx, flags, size, host_ptr); } catch (error &e) { - ret_error(errcode_ret, e); + ret_error(r_errcode, e); return NULL; } PUBLIC cl_mem -clCreateSubBuffer(cl_mem obj, cl_mem_flags flags, cl_buffer_create_type op, - const void *op_info, cl_int *errcode_ret) try { - root_buffer *parent = dynamic_cast<root_buffer *>(obj); - - if (!parent) - throw error(CL_INVALID_MEM_OBJECT); +clCreateSubBuffer(cl_mem d_mem, cl_mem_flags flags, + cl_buffer_create_type op, + const void *op_info, cl_int *r_errcode) try { + auto &parent = obj<root_buffer>(d_mem); if ((flags & (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR)) || - (~flags & parent->flags() & (CL_MEM_READ_ONLY | - CL_MEM_WRITE_ONLY))) + (~flags & parent.flags() & (CL_MEM_READ_ONLY | + CL_MEM_WRITE_ONLY))) throw error(CL_INVALID_VALUE); if (op == CL_BUFFER_CREATE_TYPE_REGION) { - const cl_buffer_region *reg = (const cl_buffer_region *)op_info; + auto reg = reinterpret_cast<const cl_buffer_region *>(op_info); if (!reg || - reg->origin > parent->size() || - reg->origin + reg->size > parent->size()) + reg->origin > parent.size() || + reg->origin + reg->size > parent.size()) throw error(CL_INVALID_VALUE); if (!reg->size) throw error(CL_INVALID_BUFFER_SIZE); - ret_error(errcode_ret, CL_SUCCESS); - return new sub_buffer(*parent, flags, reg->origin, reg->size); + ret_error(r_errcode, CL_SUCCESS); + return new sub_buffer(parent, flags, reg->origin, reg->size); } else { throw error(CL_INVALID_VALUE); } } catch (error &e) { - ret_error(errcode_ret, e); + ret_error(r_errcode, e); return NULL; } @@ -94,7 +91,7 @@ PUBLIC cl_mem clCreateImage2D(cl_context d_ctx, cl_mem_flags flags, const cl_image_format *format, size_t width, size_t height, size_t row_pitch, - void *host_ptr, cl_int *errcode_ret) try { + void *host_ptr, cl_int *r_errcode) try { auto &ctx = obj(d_ctx); if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | @@ -115,12 +112,12 @@ clCreateImage2D(cl_context d_ctx, cl_mem_flags flags, if (!supported_formats(ctx, CL_MEM_OBJECT_IMAGE2D).count(*format)) throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED); - ret_error(errcode_ret, CL_SUCCESS); + ret_error(r_errcode, CL_SUCCESS); return new image2d(ctx, flags, format, width, height, row_pitch, host_ptr); } catch (error &e) { - ret_error(errcode_ret, e); + ret_error(r_errcode, e); return NULL; } @@ -129,7 +126,7 @@ clCreateImage3D(cl_context d_ctx, cl_mem_flags flags, const cl_image_format *format, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, - void *host_ptr, cl_int *errcode_ret) try { + void *host_ptr, cl_int *r_errcode) try { auto &ctx = obj(d_ctx); if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | @@ -150,19 +147,19 @@ clCreateImage3D(cl_context d_ctx, cl_mem_flags flags, if (!supported_formats(ctx, CL_MEM_OBJECT_IMAGE3D).count(*format)) throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED); - ret_error(errcode_ret, CL_SUCCESS); + ret_error(r_errcode, CL_SUCCESS); return new image3d(ctx, flags, format, width, height, depth, row_pitch, slice_pitch, host_ptr); } catch (error &e) { - ret_error(errcode_ret, e); + ret_error(r_errcode, e); return NULL; } PUBLIC cl_int clGetSupportedImageFormats(cl_context d_ctx, cl_mem_flags flags, cl_mem_object_type type, cl_uint count, - cl_image_format *buf, cl_uint *count_ret) try { + cl_image_format *r_buf, cl_uint *r_count) try { auto &ctx = obj(d_ctx); if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | @@ -170,16 +167,18 @@ clGetSupportedImageFormats(cl_context d_ctx, cl_mem_flags flags, CL_MEM_COPY_HOST_PTR)) throw error(CL_INVALID_VALUE); - if (!count && buf) + if (r_buf && !r_count) throw error(CL_INVALID_VALUE); auto formats = supported_formats(ctx, type); - if (buf) - std::copy_n(formats.begin(), std::min((cl_uint)formats.size(), count), - buf); - if (count_ret) - *count_ret = formats.size(); + if (r_buf) + std::copy_n(formats.begin(), + std::min((cl_uint)formats.size(), count), + r_buf); + + if (r_count) + *r_count = formats.size(); return CL_SUCCESS; @@ -188,28 +187,26 @@ clGetSupportedImageFormats(cl_context d_ctx, cl_mem_flags flags, } PUBLIC cl_int -clGetMemObjectInfo(cl_mem obj, cl_mem_info param, +clGetMemObjectInfo(cl_mem d_mem, cl_mem_info param, size_t size, void *r_buf, size_t *r_size) try { property_buffer buf { r_buf, size, r_size }; - - if (!obj) - return CL_INVALID_MEM_OBJECT; + auto &mem = obj(d_mem); switch (param) { case CL_MEM_TYPE: - buf.as_scalar<cl_mem_object_type>() = obj->type(); + buf.as_scalar<cl_mem_object_type>() = mem.type(); break; case CL_MEM_FLAGS: - buf.as_scalar<cl_mem_flags>() = obj->flags(); + buf.as_scalar<cl_mem_flags>() = mem.flags(); break; case CL_MEM_SIZE: - buf.as_scalar<size_t>() = obj->size(); + buf.as_scalar<size_t>() = mem.size(); break; case CL_MEM_HOST_PTR: - buf.as_scalar<void *>() = obj->host_ptr(); + buf.as_scalar<void *>() = mem.host_ptr(); break; case CL_MEM_MAP_COUNT: @@ -217,20 +214,20 @@ clGetMemObjectInfo(cl_mem obj, cl_mem_info param, break; case CL_MEM_REFERENCE_COUNT: - buf.as_scalar<cl_uint>() = obj->ref_count(); + buf.as_scalar<cl_uint>() = mem.ref_count(); break; case CL_MEM_CONTEXT: - buf.as_scalar<cl_context>() = &obj->ctx; + buf.as_scalar<cl_context>() = desc(mem.ctx); break; case CL_MEM_ASSOCIATED_MEMOBJECT: { - sub_buffer *sub = dynamic_cast<sub_buffer *>(obj); - buf.as_scalar<cl_mem>() = (sub ? &sub->parent : NULL); + sub_buffer *sub = dynamic_cast<sub_buffer *>(&mem); + buf.as_scalar<cl_mem>() = (sub ? desc(sub->parent) : NULL); break; } case CL_MEM_OFFSET: { - sub_buffer *sub = dynamic_cast<sub_buffer *>(obj); + sub_buffer *sub = dynamic_cast<sub_buffer *>(&mem); buf.as_scalar<size_t>() = (sub ? sub->offset() : 0); break; } @@ -245,17 +242,14 @@ clGetMemObjectInfo(cl_mem obj, cl_mem_info param, } PUBLIC cl_int -clGetImageInfo(cl_mem obj, cl_image_info param, +clGetImageInfo(cl_mem d_mem, cl_image_info param, size_t size, void *r_buf, size_t *r_size) try { property_buffer buf { r_buf, size, r_size }; - image *img = dynamic_cast<image *>(obj); - - if (!img) - return CL_INVALID_MEM_OBJECT; + auto &img = obj<image>(d_mem); switch (param) { case CL_IMAGE_FORMAT: - buf.as_scalar<cl_image_format>() = img->format(); + buf.as_scalar<cl_image_format>() = img.format(); break; case CL_IMAGE_ELEMENT_SIZE: @@ -263,23 +257,23 @@ clGetImageInfo(cl_mem obj, cl_image_info param, break; case CL_IMAGE_ROW_PITCH: - buf.as_scalar<size_t>() = img->row_pitch(); + buf.as_scalar<size_t>() = img.row_pitch(); break; case CL_IMAGE_SLICE_PITCH: - buf.as_scalar<size_t>() = img->slice_pitch(); + buf.as_scalar<size_t>() = img.slice_pitch(); break; case CL_IMAGE_WIDTH: - buf.as_scalar<size_t>() = img->width(); + buf.as_scalar<size_t>() = img.width(); break; case CL_IMAGE_HEIGHT: - buf.as_scalar<size_t>() = img->height(); + buf.as_scalar<size_t>() = img.height(); break; case CL_IMAGE_DEPTH: - buf.as_scalar<size_t>() = img->depth(); + buf.as_scalar<size_t>() = img.depth(); break; default: @@ -293,36 +287,38 @@ clGetImageInfo(cl_mem obj, cl_image_info param, } PUBLIC cl_int -clRetainMemObject(cl_mem obj) { - if (!obj) - return CL_INVALID_MEM_OBJECT; - - obj->retain(); +clRetainMemObject(cl_mem d_mem) try { + obj(d_mem).retain(); return CL_SUCCESS; + +} catch (error &e) { + return e.get(); } PUBLIC cl_int -clReleaseMemObject(cl_mem obj) { - if (!obj) - return CL_INVALID_MEM_OBJECT; - - if (obj->release()) - delete obj; +clReleaseMemObject(cl_mem d_mem) try { + if (obj(d_mem).release()) + delete pobj(d_mem); return CL_SUCCESS; + +} catch (error &e) { + return e.get(); } PUBLIC cl_int -clSetMemObjectDestructorCallback(cl_mem obj, +clSetMemObjectDestructorCallback(cl_mem d_mem, void (CL_CALLBACK *pfn_notify)(cl_mem, void *), - void *user_data) { - if (!obj) - return CL_INVALID_MEM_OBJECT; + void *user_data) try { + auto &mem = obj(d_mem); if (!pfn_notify) return CL_INVALID_VALUE; - obj->destroy_notify([=]{ pfn_notify(obj, user_data); }); + mem.destroy_notify([=]{ pfn_notify(d_mem, user_data); }); return CL_SUCCESS; + +} catch (error &e) { + return e.get(); } diff --git a/src/gallium/state_trackers/clover/api/transfer.cpp b/src/gallium/state_trackers/clover/api/transfer.cpp index f91da617b68..e6fa26ca4e4 100644 --- a/src/gallium/state_trackers/clover/api/transfer.cpp +++ b/src/gallium/state_trackers/clover/api/transfer.cpp @@ -40,27 +40,17 @@ namespace { /// Common argument checking shared by memory transfer commands. /// void - validate_base(command_queue &q, cl_uint num_deps, const cl_event *deps) { - if (bool(num_deps) != bool(deps) || - any_of(is_zero(), range(deps, num_deps))) - throw error(CL_INVALID_EVENT_WAIT_LIST); - - if (any_of([&](const cl_event ev) { - return &obj(ev).ctx != &q.ctx; - }, range(deps, num_deps))) + validate_common(command_queue &q, + std::initializer_list<std::reference_wrapper<memory_obj>> mems, + const ref_vector<event> &deps) { + if (any_of([&](const event &ev) { + return &ev.ctx != &q.ctx; + }, deps)) throw error(CL_INVALID_CONTEXT); - } - /// - /// Memory object-specific argument checking shared by most memory - /// transfer commands. - /// - void - validate_obj(command_queue &q, cl_mem mem) { - if (!mem) - throw error(CL_INVALID_MEM_OBJECT); - - if (&mem->ctx != &q.ctx) + if (any_of([&](const memory_obj &mem) { + return &mem.ctx != &q.ctx; + }, mems)) throw error(CL_INVALID_CONTEXT); } @@ -69,44 +59,45 @@ namespace { /// \a T. The return value of get() should be implicitly /// convertible to \a void *. /// - template<typename T> struct _map; + template<typename T> + struct _map { + static mapping + get(command_queue &q, T obj, cl_map_flags flags, + size_t offset, size_t size) { + return { q, obj->resource(q), flags, true, + {{ offset }}, {{ size, 1, 1 }} }; + } + }; - template<> struct _map<void *> { + template<> + struct _map<void *> { static void * - get(cl_command_queue q, void *obj, cl_map_flags flags, + get(command_queue &q, void *obj, cl_map_flags flags, size_t offset, size_t size) { return (char *)obj + offset; } }; - template<> struct _map<const void *> { + template<> + struct _map<const void *> { static const void * - get(cl_command_queue q, const void *obj, cl_map_flags flags, + get(command_queue &q, const void *obj, cl_map_flags flags, size_t offset, size_t size) { return (const char *)obj + offset; } }; - template<> struct _map<memory_obj *> { - static mapping - get(cl_command_queue q, memory_obj *mem, cl_map_flags flags, - size_t offset, size_t size) {< - return { obj(q), mem->resource(obj(q)), flags, true, - {{ offset }}, {{ size, 1, 1 }}}; - } - }; - /// /// Software copy from \a src_obj to \a dst_obj. They can be /// either pointers or memory objects. /// template<typename T, typename S> std::function<void (event &)> - soft_copy_op(cl_command_queue q, + soft_copy_op(command_queue &q, T dst_obj, const vector_t &dst_orig, const vector_t &dst_pitch, S src_obj, const vector_t &src_orig, const vector_t &src_pitch, const vector_t ®ion) { - return [=](event &) { + return [=, &q](event &) { auto dst = _map<T>::get(q, dst_obj, CL_MAP_WRITE, dot(dst_pitch, dst_orig), dst_pitch[2] * region[2]); @@ -141,24 +132,24 @@ namespace { } PUBLIC cl_int -clEnqueueReadBuffer(cl_command_queue d_q, cl_mem mem, cl_bool blocking, +clEnqueueReadBuffer(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking, size_t offset, size_t size, void *ptr, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev) try { auto &q = obj(d_q); + auto &mem = obj(d_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - validate_base(q, num_deps, d_deps); - validate_obj(q, mem); + validate_common(q, { mem }, deps); - if (!ptr || offset > mem->size() || offset + size > mem->size()) + if (!ptr || offset > mem.size() || offset + size > mem.size()) throw error(CL_INVALID_VALUE); hard_event *hev = new hard_event( q, CL_COMMAND_READ_BUFFER, deps, - soft_copy_op(d_q, + soft_copy_op(q, ptr, {{ 0 }}, {{ 1 }}, - mem, {{ offset }}, {{ 1 }}, + &mem, {{ offset }}, {{ 1 }}, {{ size, 1, 1 }})); ret_object(rd_ev, hev); @@ -169,23 +160,23 @@ clEnqueueReadBuffer(cl_command_queue d_q, cl_mem mem, cl_bool blocking, } PUBLIC cl_int -clEnqueueWriteBuffer(cl_command_queue d_q, cl_mem mem, cl_bool blocking, +clEnqueueWriteBuffer(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking, size_t offset, size_t size, const void *ptr, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev) try { auto &q = obj(d_q); + auto &mem = obj(d_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - validate_base(q, num_deps, d_deps); - validate_obj(q, mem); + validate_common(q, { mem }, deps); - if (!ptr || offset > mem->size() || offset + size > mem->size()) + if (!ptr || offset > mem.size() || offset + size > mem.size()) throw error(CL_INVALID_VALUE); hard_event *hev = new hard_event( q, CL_COMMAND_WRITE_BUFFER, deps, - soft_copy_op(d_q, - mem, {{ offset }}, {{ 1 }}, + soft_copy_op(q, + &mem, {{ offset }}, {{ 1 }}, ptr, {{ 0 }}, {{ 1 }}, {{ size, 1, 1 }})); @@ -197,7 +188,7 @@ clEnqueueWriteBuffer(cl_command_queue d_q, cl_mem mem, cl_bool blocking, } PUBLIC cl_int -clEnqueueReadBufferRect(cl_command_queue d_q, cl_mem mem, cl_bool blocking, +clEnqueueReadBufferRect(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking, const size_t *obj_origin, const size_t *host_origin, const size_t *region, @@ -207,20 +198,20 @@ clEnqueueReadBufferRect(cl_command_queue d_q, cl_mem mem, cl_bool blocking, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev) try { auto &q = obj(d_q); + auto &mem = obj(d_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - validate_base(q, num_deps, d_deps); - validate_obj(q, mem); + validate_common(q, { mem }, deps); if (!ptr) throw error(CL_INVALID_VALUE); hard_event *hev = new hard_event( q, CL_COMMAND_READ_BUFFER_RECT, deps, - soft_copy_op(d_q, + soft_copy_op(q, ptr, vector(host_origin), {{ 1, host_row_pitch, host_slice_pitch }}, - mem, vector(obj_origin), + &mem, vector(obj_origin), {{ 1, obj_row_pitch, obj_slice_pitch }}, vector(region))); @@ -232,7 +223,7 @@ clEnqueueReadBufferRect(cl_command_queue d_q, cl_mem mem, cl_bool blocking, } PUBLIC cl_int -clEnqueueWriteBufferRect(cl_command_queue d_q, cl_mem mem, cl_bool blocking, +clEnqueueWriteBufferRect(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking, const size_t *obj_origin, const size_t *host_origin, const size_t *region, @@ -242,18 +233,18 @@ clEnqueueWriteBufferRect(cl_command_queue d_q, cl_mem mem, cl_bool blocking, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev) try { auto &q = obj(d_q); + auto &mem = obj(d_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - validate_base(q, num_deps, d_deps); - validate_obj(q, mem); + validate_common(q, { mem }, deps); if (!ptr) throw error(CL_INVALID_VALUE); hard_event *hev = new hard_event( q, CL_COMMAND_WRITE_BUFFER_RECT, deps, - soft_copy_op(d_q, - mem, vector(obj_origin), + soft_copy_op(q, + &mem, vector(obj_origin), {{ 1, obj_row_pitch, obj_slice_pitch }}, ptr, vector(host_origin), {{ 1, host_row_pitch, host_slice_pitch }}, @@ -267,21 +258,21 @@ clEnqueueWriteBufferRect(cl_command_queue d_q, cl_mem mem, cl_bool blocking, } PUBLIC cl_int -clEnqueueCopyBuffer(cl_command_queue d_q, cl_mem src_mem, cl_mem dst_mem, +clEnqueueCopyBuffer(cl_command_queue d_q, cl_mem d_src_mem, cl_mem d_dst_mem, size_t src_offset, size_t dst_offset, size_t size, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev) try { auto &q = obj(d_q); + auto &src_mem = obj(d_src_mem); + auto &dst_mem = obj(d_dst_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - validate_base(q, num_deps, d_deps); - validate_obj(q, src_mem); - validate_obj(q, dst_mem); + validate_common(q, { src_mem, dst_mem }, deps); hard_event *hev = new hard_event( q, CL_COMMAND_COPY_BUFFER, deps, - hard_copy_op(q, dst_mem, {{ dst_offset }}, - src_mem, {{ src_offset }}, + hard_copy_op(q, &dst_mem, {{ dst_offset }}, + &src_mem, {{ src_offset }}, {{ size, 1, 1 }})); ret_object(rd_ev, hev); @@ -292,8 +283,8 @@ clEnqueueCopyBuffer(cl_command_queue d_q, cl_mem src_mem, cl_mem dst_mem, } PUBLIC cl_int -clEnqueueCopyBufferRect(cl_command_queue d_q, cl_mem src_mem, - cl_mem dst_mem, +clEnqueueCopyBufferRect(cl_command_queue d_q, cl_mem d_src_mem, + cl_mem d_dst_mem, const size_t *src_origin, const size_t *dst_origin, const size_t *region, size_t src_row_pitch, size_t src_slice_pitch, @@ -301,18 +292,18 @@ clEnqueueCopyBufferRect(cl_command_queue d_q, cl_mem src_mem, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev) try { auto &q = obj(d_q); + auto &src_mem = obj(d_src_mem); + auto &dst_mem = obj(d_dst_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - validate_base(q, num_deps, d_deps); - validate_obj(q, src_mem); - validate_obj(q, dst_mem); + validate_common(q, { src_mem, dst_mem }, deps); hard_event *hev = new hard_event( q, CL_COMMAND_COPY_BUFFER_RECT, deps, - soft_copy_op(d_q, - dst_mem, vector(dst_origin), + soft_copy_op(q, + &dst_mem, vector(dst_origin), {{ 1, dst_row_pitch, dst_slice_pitch }}, - src_mem, vector(src_origin), + &src_mem, vector(src_origin), {{ 1, src_row_pitch, src_slice_pitch }}, vector(region))); @@ -324,28 +315,27 @@ clEnqueueCopyBufferRect(cl_command_queue d_q, cl_mem src_mem, } PUBLIC cl_int -clEnqueueReadImage(cl_command_queue d_q, cl_mem mem, cl_bool blocking, +clEnqueueReadImage(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking, const size_t *origin, const size_t *region, size_t row_pitch, size_t slice_pitch, void *ptr, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev) try { auto &q = obj(d_q); + auto &img = obj<image>(d_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - image *img = dynamic_cast<image *>(mem); - validate_base(q, num_deps, d_deps); - validate_obj(q, img); + validate_common(q, { img }, deps); if (!ptr) throw error(CL_INVALID_VALUE); hard_event *hev = new hard_event( q, CL_COMMAND_READ_IMAGE, deps, - soft_copy_op(d_q, + soft_copy_op(q, ptr, {}, {{ 1, row_pitch, slice_pitch }}, - mem, vector(origin), - {{ 1, img->row_pitch(), img->slice_pitch() }}, + &img, vector(origin), + {{ 1, img.row_pitch(), img.slice_pitch() }}, vector(region))); ret_object(rd_ev, hev); @@ -356,26 +346,25 @@ clEnqueueReadImage(cl_command_queue d_q, cl_mem mem, cl_bool blocking, } PUBLIC cl_int -clEnqueueWriteImage(cl_command_queue d_q, cl_mem mem, cl_bool blocking, +clEnqueueWriteImage(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking, const size_t *origin, const size_t *region, size_t row_pitch, size_t slice_pitch, const void *ptr, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev) try { auto &q = obj(d_q); + auto &img = obj<image>(d_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - image *img = dynamic_cast<image *>(mem); - validate_base(q, num_deps, d_deps); - validate_obj(q, img); + validate_common(q, { img }, deps); if (!ptr) throw error(CL_INVALID_VALUE); hard_event *hev = new hard_event( q, CL_COMMAND_WRITE_IMAGE, deps, - soft_copy_op(d_q, - mem, vector(origin), - {{ 1, img->row_pitch(), img->slice_pitch() }}, + soft_copy_op(q, + &img, vector(origin), + {{ 1, img.row_pitch(), img.slice_pitch() }}, ptr, {}, {{ 1, row_pitch, slice_pitch }}, vector(region))); @@ -388,25 +377,23 @@ clEnqueueWriteImage(cl_command_queue d_q, cl_mem mem, cl_bool blocking, } PUBLIC cl_int -clEnqueueCopyImage(cl_command_queue d_q, cl_mem src_mem, cl_mem dst_mem, +clEnqueueCopyImage(cl_command_queue d_q, cl_mem d_src_mem, cl_mem d_dst_mem, const size_t *src_origin, const size_t *dst_origin, const size_t *region, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev) try { auto &q = obj(d_q); + auto &src_img = obj<image>(d_src_mem); + auto &dst_img = obj<image>(d_dst_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - image *src_img = dynamic_cast<image *>(src_mem); - image *dst_img = dynamic_cast<image *>(dst_mem); - validate_base(q, num_deps, d_deps); - validate_obj(q, src_img); - validate_obj(q, dst_img); + validate_common(q, { src_img, dst_img }, deps); hard_event *hev = new hard_event( q, CL_COMMAND_COPY_IMAGE, deps, hard_copy_op(q, - dst_img, vector(dst_origin), - src_img, vector(src_origin), + &dst_img, vector(dst_origin), + &src_img, vector(src_origin), vector(region))); ret_object(rd_ev, hev); @@ -418,26 +405,25 @@ clEnqueueCopyImage(cl_command_queue d_q, cl_mem src_mem, cl_mem dst_mem, PUBLIC cl_int clEnqueueCopyImageToBuffer(cl_command_queue d_q, - cl_mem src_mem, cl_mem dst_mem, + cl_mem d_src_mem, cl_mem d_dst_mem, const size_t *src_origin, const size_t *region, size_t dst_offset, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev) try { auto &q = obj(d_q); + auto &src_img = obj<image>(d_src_mem); + auto &dst_mem = obj(d_dst_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - image *src_img = dynamic_cast<image *>(src_mem); - validate_base(q, num_deps, d_deps); - validate_obj(q, src_img); - validate_obj(q, dst_mem); + validate_common(q, { src_img, dst_mem }, deps); hard_event *hev = new hard_event( q, CL_COMMAND_COPY_IMAGE_TO_BUFFER, deps, - soft_copy_op(d_q, - dst_mem, {{ dst_offset }}, + soft_copy_op(q, + &dst_mem, {{ dst_offset }}, {{ 0, 0, 0 }}, - src_mem, vector(src_origin), - {{ 1, src_img->row_pitch(), src_img->slice_pitch() }}, + &src_img, vector(src_origin), + {{ 1, src_img.row_pitch(), src_img.slice_pitch() }}, vector(region))); ret_object(rd_ev, hev); @@ -449,25 +435,24 @@ clEnqueueCopyImageToBuffer(cl_command_queue d_q, PUBLIC cl_int clEnqueueCopyBufferToImage(cl_command_queue d_q, - cl_mem src_mem, cl_mem dst_mem, + cl_mem d_src_mem, cl_mem d_dst_mem, size_t src_offset, const size_t *dst_origin, const size_t *region, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev) try { auto &q = obj(d_q); + auto &src_mem = obj(d_src_mem); + auto &dst_img = obj<image>(d_dst_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - image *dst_img = dynamic_cast<image *>(dst_mem); - validate_base(q, num_deps, d_deps); - validate_obj(q, src_mem); - validate_obj(q, dst_img); + validate_common(q, { src_mem, dst_img }, deps); hard_event *hev = new hard_event( q, CL_COMMAND_COPY_BUFFER_TO_IMAGE, deps, - soft_copy_op(d_q, - dst_mem, vector(dst_origin), - {{ 1, dst_img->row_pitch(), dst_img->slice_pitch() }}, - src_mem, {{ src_offset }}, + soft_copy_op(q, + &dst_img, vector(dst_origin), + {{ 1, dst_img.row_pitch(), dst_img.slice_pitch() }}, + &src_mem, {{ src_offset }}, {{ 0, 0, 0 }}, vector(region))); @@ -479,20 +464,20 @@ clEnqueueCopyBufferToImage(cl_command_queue d_q, } PUBLIC void * -clEnqueueMapBuffer(cl_command_queue d_q, cl_mem mem, cl_bool blocking, +clEnqueueMapBuffer(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking, cl_map_flags flags, size_t offset, size_t size, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev, cl_int *r_errcode) try { auto &q = obj(d_q); + auto &mem = obj(d_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - validate_base(q, num_deps, d_deps); - validate_obj(q, mem); + validate_common(q, { mem }, deps); - if (offset > mem->size() || offset + size > mem->size()) + if (offset > mem.size() || offset + size > mem.size()) throw error(CL_INVALID_VALUE); - void *map = mem->resource(q).add_map( + void *map = mem.resource(q).add_map( q, flags, blocking, {{ offset }}, {{ size }}); ret_object(rd_ev, new hard_event(q, CL_COMMAND_MAP_BUFFER, deps)); @@ -505,20 +490,19 @@ clEnqueueMapBuffer(cl_command_queue d_q, cl_mem mem, cl_bool blocking, } PUBLIC void * -clEnqueueMapImage(cl_command_queue d_q, cl_mem mem, cl_bool blocking, +clEnqueueMapImage(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking, cl_map_flags flags, const size_t *origin, const size_t *region, size_t *row_pitch, size_t *slice_pitch, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev, cl_int *r_errcode) try { auto &q = obj(d_q); + auto &img = obj<image>(d_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - image *img = dynamic_cast<image *>(mem); - validate_base(q, num_deps, d_deps); - validate_obj(q, img); + validate_common(q, { img }, deps); - void *map = img->resource(q).add_map( + void *map = img.resource(q).add_map( q, flags, blocking, vector(origin), vector(region)); ret_object(rd_ev, new hard_event(q, CL_COMMAND_MAP_IMAGE, deps)); @@ -531,19 +515,19 @@ clEnqueueMapImage(cl_command_queue d_q, cl_mem mem, cl_bool blocking, } PUBLIC cl_int -clEnqueueUnmapMemObject(cl_command_queue d_q, cl_mem mem, void *ptr, +clEnqueueUnmapMemObject(cl_command_queue d_q, cl_mem d_mem, void *ptr, cl_uint num_deps, const cl_event *d_deps, cl_event *rd_ev) try { auto &q = obj(d_q); + auto &mem = obj(d_mem); auto deps = objs<wait_list_tag>(d_deps, num_deps); - validate_base(q, num_deps, d_deps); - validate_obj(q, mem); + validate_common(q, { mem }, deps); hard_event *hev = new hard_event( q, CL_COMMAND_UNMAP_MEM_OBJECT, deps, [=, &q, &mem](event &) { - mem->resource(q).del_map(ptr); + mem.resource(q).del_map(ptr); }); ret_object(rd_ev, hev); |