diff options
author | Francisco Jerez <[email protected]> | 2013-09-15 20:50:30 -0700 |
---|---|---|
committer | Francisco Jerez <[email protected]> | 2013-10-21 10:47:02 -0700 |
commit | 9d06fb8fa86a70d1c3a4924960dfebabaf1fa3bf (patch) | |
tree | 708545cb0163f56b3dcce9ee3702a0c5ced4417b /src/gallium/state_trackers | |
parent | c9e009b74d4ca4c471d3d77960f232035876aaa8 (diff) |
clover: Switch context objects to the new model.
Tested-by: Tom Stellard <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers')
-rw-r--r-- | src/gallium/state_trackers/clover/api/context.cpp | 74 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/api/event.cpp | 7 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/api/memory.cpp | 21 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/api/program.cpp | 22 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/api/queue.cpp | 10 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/api/sampler.cpp | 7 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/core/context.cpp | 10 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/core/context.hpp | 30 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/core/device.hpp | 2 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/core/error.hpp | 2 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/core/format.cpp | 4 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/core/format.hpp | 2 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/core/object.hpp | 3 |
13 files changed, 91 insertions, 103 deletions
diff --git a/src/gallium/state_trackers/clover/api/context.cpp b/src/gallium/state_trackers/clover/api/context.cpp index a03b9bb15c8..ca05efc2d95 100644 --- a/src/gallium/state_trackers/clover/api/context.cpp +++ b/src/gallium/state_trackers/clover/api/context.cpp @@ -26,99 +26,97 @@ using namespace clover; PUBLIC cl_context -clCreateContext(const cl_context_properties *props, cl_uint num_devs, +clCreateContext(const cl_context_properties *d_props, cl_uint num_devs, const cl_device_id *d_devs, void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *), - void *user_data, cl_int *errcode_ret) try { - auto devs = map(addresses(), objs(d_devs, num_devs)); - auto mprops = property_map(props); + void *user_data, cl_int *r_errcode) try { + auto props = property_map(d_props); + auto devs = objs(d_devs, num_devs); if (!pfn_notify && user_data) throw error(CL_INVALID_VALUE); - for (auto p : mprops) { - if (p.first != CL_CONTEXT_PLATFORM) + for (auto prop : props) { + if (prop.first != CL_CONTEXT_PLATFORM) throw error(CL_INVALID_PROPERTY); } - ret_error(errcode_ret, CL_SUCCESS); - return new context(property_vector(mprops), devs); + ret_error(r_errcode, CL_SUCCESS); + return desc(new context(property_vector(props), devs)); -} catch(error &e) { - ret_error(errcode_ret, e); +} catch (error &e) { + ret_error(r_errcode, e); return NULL; } PUBLIC cl_context -clCreateContextFromType(const cl_context_properties *props, +clCreateContextFromType(const cl_context_properties *d_props, cl_device_type type, void (CL_CALLBACK *pfn_notify)( const char *, const void *, size_t, void *), - void *user_data, cl_int *errcode_ret) try { - cl_platform_id platform; + void *user_data, cl_int *r_errcode) try { + cl_platform_id d_platform; cl_uint num_platforms; - cl_device_id dev; + cl_device_id d_dev; cl_int ret; - ret = clGetPlatformIDs(1, &platform, &num_platforms); + ret = clGetPlatformIDs(1, &d_platform, &num_platforms); if (ret || !num_platforms) throw error(CL_INVALID_PLATFORM); - ret = clGetDeviceIDs(platform, type, 1, &dev, 0); + ret = clGetDeviceIDs(d_platform, type, 1, &d_dev, 0); if (ret) throw error(CL_DEVICE_NOT_FOUND); - return clCreateContext(props, 1, &dev, pfn_notify, user_data, errcode_ret); + return clCreateContext(d_props, 1, &d_dev, pfn_notify, user_data, r_errcode); -} catch(error &e) { - ret_error(errcode_ret, e); +} catch (error &e) { + ret_error(r_errcode, e); return NULL; } PUBLIC cl_int -clRetainContext(cl_context ctx) { - if (!ctx) - return CL_INVALID_CONTEXT; - - ctx->retain(); +clRetainContext(cl_context d_ctx) try { + obj(d_ctx).retain(); return CL_SUCCESS; + +} catch (error &e) { + return e.get(); } PUBLIC cl_int -clReleaseContext(cl_context ctx) { - if (!ctx) - return CL_INVALID_CONTEXT; - - if (ctx->release()) - delete ctx; +clReleaseContext(cl_context d_ctx) try { + if (obj(d_ctx).release()) + delete pobj(d_ctx); return CL_SUCCESS; + +} catch (error &e) { + return e.get(); } PUBLIC cl_int -clGetContextInfo(cl_context ctx, cl_context_info param, +clGetContextInfo(cl_context d_ctx, cl_context_info param, size_t size, void *r_buf, size_t *r_size) try { property_buffer buf { r_buf, size, r_size }; - - if (!ctx) - return CL_INVALID_CONTEXT; + auto &ctx = obj(d_ctx); switch (param) { case CL_CONTEXT_REFERENCE_COUNT: - buf.as_scalar<cl_uint>() = ctx->ref_count(); + buf.as_scalar<cl_uint>() = ctx.ref_count(); break; case CL_CONTEXT_NUM_DEVICES: - buf.as_scalar<cl_uint>() = ctx->devs.size(); + buf.as_scalar<cl_uint>() = ctx.devs.size(); break; case CL_CONTEXT_DEVICES: - buf.as_vector<cl_device_id>() = ctx->devs; + buf.as_vector<cl_device_id>() = descs(map(derefs(), ctx.devs)); break; case CL_CONTEXT_PROPERTIES: - buf.as_vector<cl_context_properties>() = ctx->props(); + buf.as_vector<cl_context_properties>() = ctx.props(); break; default: diff --git a/src/gallium/state_trackers/clover/api/event.cpp b/src/gallium/state_trackers/clover/api/event.cpp index b2ab78ecc05..db3a4062cc6 100644 --- a/src/gallium/state_trackers/clover/api/event.cpp +++ b/src/gallium/state_trackers/clover/api/event.cpp @@ -26,12 +26,11 @@ using namespace clover; PUBLIC cl_event -clCreateUserEvent(cl_context ctx, cl_int *errcode_ret) try { - if (!ctx) - throw error(CL_INVALID_CONTEXT); +clCreateUserEvent(cl_context d_ctx, cl_int *errcode_ret) try { + auto &ctx = obj(d_ctx); ret_error(errcode_ret, CL_SUCCESS); - return new soft_event(*ctx, {}, false); + return new soft_event(ctx, {}, false); } catch(error &e) { ret_error(errcode_ret, e); diff --git a/src/gallium/state_trackers/clover/api/memory.cpp b/src/gallium/state_trackers/clover/api/memory.cpp index 112094a84c9..b6b82f8d425 100644 --- a/src/gallium/state_trackers/clover/api/memory.cpp +++ b/src/gallium/state_trackers/clover/api/memory.cpp @@ -45,7 +45,7 @@ clCreateBuffer(cl_context ctx, cl_mem_flags flags, size_t size, throw error(CL_INVALID_VALUE); ret_error(errcode_ret, CL_SUCCESS); - return new root_buffer(*ctx, flags, size, host_ptr); + return new root_buffer(obj(ctx), flags, size, host_ptr); } catch (error &e) { ret_error(errcode_ret, e); @@ -91,12 +91,11 @@ clCreateSubBuffer(cl_mem obj, cl_mem_flags flags, cl_buffer_create_type op, } PUBLIC cl_mem -clCreateImage2D(cl_context ctx, cl_mem_flags flags, +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 { - if (!ctx) - throw error(CL_INVALID_CONTEXT); + auto &ctx = obj(d_ctx); if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | @@ -117,7 +116,7 @@ clCreateImage2D(cl_context ctx, cl_mem_flags flags, throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED); ret_error(errcode_ret, CL_SUCCESS); - return new image2d(*ctx, flags, format, width, height, + return new image2d(ctx, flags, format, width, height, row_pitch, host_ptr); } catch (error &e) { @@ -126,13 +125,12 @@ clCreateImage2D(cl_context ctx, cl_mem_flags flags, } PUBLIC cl_mem -clCreateImage3D(cl_context ctx, cl_mem_flags flags, +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 { - if (!ctx) - throw error(CL_INVALID_CONTEXT); + auto &ctx = obj(d_ctx); if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | @@ -153,7 +151,7 @@ clCreateImage3D(cl_context ctx, cl_mem_flags flags, throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED); ret_error(errcode_ret, CL_SUCCESS); - return new image3d(*ctx, flags, format, width, height, depth, + return new image3d(ctx, flags, format, width, height, depth, row_pitch, slice_pitch, host_ptr); } catch (error &e) { @@ -162,11 +160,10 @@ clCreateImage3D(cl_context ctx, cl_mem_flags flags, } PUBLIC cl_int -clGetSupportedImageFormats(cl_context ctx, cl_mem_flags flags, +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 { - if (!ctx) - throw error(CL_INVALID_CONTEXT); + auto &ctx = obj(d_ctx); if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp index 5d6dd040ad5..f6c12f40367 100644 --- a/src/gallium/state_trackers/clover/api/program.cpp +++ b/src/gallium/state_trackers/clover/api/program.cpp @@ -26,14 +26,12 @@ using namespace clover; PUBLIC cl_program -clCreateProgramWithSource(cl_context ctx, cl_uint count, +clCreateProgramWithSource(cl_context d_ctx, cl_uint count, const char **strings, const size_t *lengths, cl_int *errcode_ret) try { + auto &ctx = obj(d_ctx); std::string source; - if (!ctx) - throw error(CL_INVALID_CONTEXT); - if (!count || !strings || any_of(is_zero(), range(strings, count))) throw error(CL_INVALID_VALUE); @@ -46,7 +44,7 @@ clCreateProgramWithSource(cl_context ctx, cl_uint count, // ...and create a program object for them. ret_error(errcode_ret, CL_SUCCESS); - return new program(*ctx, source); + return new program(ctx, source); } catch (error &e) { ret_error(errcode_ret, e); @@ -54,20 +52,18 @@ clCreateProgramWithSource(cl_context ctx, cl_uint count, } PUBLIC cl_program -clCreateProgramWithBinary(cl_context ctx, cl_uint n, +clCreateProgramWithBinary(cl_context d_ctx, cl_uint n, const cl_device_id *d_devs, const size_t *lengths, const unsigned char **binaries, cl_int *status_ret, cl_int *errcode_ret) try { + auto &ctx = obj(d_ctx); auto devs = objs(d_devs, n); - if (!ctx) - throw error(CL_INVALID_CONTEXT); - if (!lengths || !binaries) throw error(CL_INVALID_VALUE); if (any_of([&](device &dev) { - return !ctx->has_device(&dev); + return !ctx.has_device(dev); }, devs)) throw error(CL_INVALID_DEVICE); @@ -102,7 +98,7 @@ clCreateProgramWithBinary(cl_context ctx, cl_uint n, // initialize a program object with them. ret_error(errcode_ret, CL_SUCCESS); - return new program(*ctx, map(addresses(), devs), map(values(), modules)); + return new program(ctx, map(addresses(), devs), map(values(), modules)); } catch (error &e) { ret_error(errcode_ret, e); @@ -145,7 +141,7 @@ clBuildProgram(cl_program prog, cl_uint count, const cl_device_id *devs, if (devs) { if (any_of([&](const cl_device_id dev) { - return !prog->ctx.has_device(pobj(dev)); + return !prog->ctx.has_device(obj(dev)); }, range(devs, count))) throw error(CL_INVALID_DEVICE); @@ -235,7 +231,7 @@ clGetProgramBuildInfo(cl_program prog, cl_device_id dev, if (!prog) return CL_INVALID_PROGRAM; - if (!prog->ctx.has_device(pobj(dev))) + if (!prog->ctx.has_device(obj(dev))) return CL_INVALID_DEVICE; switch (param) { diff --git a/src/gallium/state_trackers/clover/api/queue.cpp b/src/gallium/state_trackers/clover/api/queue.cpp index 8e500fa03ed..ba459250f94 100644 --- a/src/gallium/state_trackers/clover/api/queue.cpp +++ b/src/gallium/state_trackers/clover/api/queue.cpp @@ -26,15 +26,13 @@ using namespace clover; PUBLIC cl_command_queue -clCreateCommandQueue(cl_context ctx, cl_device_id d_dev, +clCreateCommandQueue(cl_context d_ctx, cl_device_id d_dev, cl_command_queue_properties props, cl_int *errcode_ret) try { + auto &ctx = obj(d_ctx); auto &dev = obj(d_dev); - if (!ctx) - throw error(CL_INVALID_CONTEXT); - - if (!ctx->has_device(&dev)) + if (!ctx.has_device(dev)) throw error(CL_INVALID_DEVICE); if (props & ~(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | @@ -42,7 +40,7 @@ clCreateCommandQueue(cl_context ctx, cl_device_id d_dev, throw error(CL_INVALID_VALUE); ret_error(errcode_ret, CL_SUCCESS); - return new command_queue(*ctx, dev, props); + return new command_queue(ctx, dev, props); } catch (error &e) { ret_error(errcode_ret, e); diff --git a/src/gallium/state_trackers/clover/api/sampler.cpp b/src/gallium/state_trackers/clover/api/sampler.cpp index 84d5d643154..846f8d4fe33 100644 --- a/src/gallium/state_trackers/clover/api/sampler.cpp +++ b/src/gallium/state_trackers/clover/api/sampler.cpp @@ -26,14 +26,13 @@ using namespace clover; PUBLIC cl_sampler -clCreateSampler(cl_context ctx, cl_bool norm_mode, +clCreateSampler(cl_context d_ctx, cl_bool norm_mode, cl_addressing_mode addr_mode, cl_filter_mode filter_mode, cl_int *errcode_ret) try { - if (!ctx) - throw error(CL_INVALID_CONTEXT); + auto &ctx = obj(d_ctx); ret_error(errcode_ret, CL_SUCCESS); - return new sampler(*ctx, norm_mode, addr_mode, filter_mode); + return new sampler(ctx, norm_mode, addr_mode, filter_mode); } catch (error &e) { ret_error(errcode_ret, e); diff --git a/src/gallium/state_trackers/clover/core/context.cpp b/src/gallium/state_trackers/clover/core/context.cpp index 31e75bdaa70..7293f9406f2 100644 --- a/src/gallium/state_trackers/clover/core/context.cpp +++ b/src/gallium/state_trackers/clover/core/context.cpp @@ -26,12 +26,12 @@ using namespace clover; -_cl_context::_cl_context(const std::vector<cl_context_properties> &props, - const std::vector<device *> &devs) : - devs(devs), _props(props) { +context::context(const std::vector<cl_context_properties> &props, + const ref_vector<device> &devs) : + devs(map(addresses(), devs)), _props(props) { } bool -_cl_context::has_device(clover::device *dev) const { - return std::count(devs.begin(), devs.end(), dev); +context::has_device(device &dev) const { + return std::count(devs.begin(), devs.end(), &dev); } diff --git a/src/gallium/state_trackers/clover/core/context.hpp b/src/gallium/state_trackers/clover/core/context.hpp index a4902dd7b90..7ef3db9b9d3 100644 --- a/src/gallium/state_trackers/clover/core/context.hpp +++ b/src/gallium/state_trackers/clover/core/context.hpp @@ -27,25 +27,23 @@ #include "core/device.hpp" namespace clover { - typedef struct _cl_context context; -} - -struct _cl_context : public clover::ref_counter { -public: - _cl_context(const std::vector<cl_context_properties> &props, - const std::vector<clover::device *> &devs); - _cl_context(const _cl_context &ctx) = delete; + class context : public ref_counter, public _cl_context { + public: + context(const std::vector<cl_context_properties> &props, + const ref_vector<device> &devs); + context(const context &ctx) = delete; - bool has_device(clover::device *dev) const; + bool has_device(device &dev) const; - const std::vector<cl_context_properties> &props() const { - return _props; - } + const std::vector<cl_context_properties> &props() const { + return _props; + } - const std::vector<clover::device *> devs; + const std::vector<device *> devs; -private: - std::vector<cl_context_properties> _props; -}; + private: + std::vector<cl_context_properties> _props; + }; +} #endif diff --git a/src/gallium/state_trackers/clover/core/device.hpp b/src/gallium/state_trackers/clover/core/device.hpp index 23a931b03cd..c490b20edc2 100644 --- a/src/gallium/state_trackers/clover/core/device.hpp +++ b/src/gallium/state_trackers/clover/core/device.hpp @@ -70,7 +70,7 @@ namespace clover { friend class root_resource; friend class hard_event; friend std::set<cl_image_format> - supported_formats(cl_context, cl_mem_object_type); + supported_formats(const context &, cl_mem_object_type); clover::platform &platform; diff --git a/src/gallium/state_trackers/clover/core/error.hpp b/src/gallium/state_trackers/clover/core/error.hpp index 34982810013..9448a70d54a 100644 --- a/src/gallium/state_trackers/clover/core/error.hpp +++ b/src/gallium/state_trackers/clover/core/error.hpp @@ -29,7 +29,7 @@ namespace clover { typedef struct _cl_command_queue command_queue; - typedef struct _cl_context context; + class context; class device; typedef struct _cl_event event; class hard_event; diff --git a/src/gallium/state_trackers/clover/core/format.cpp b/src/gallium/state_trackers/clover/core/format.cpp index d0c01530bbf..40d5ded1d76 100644 --- a/src/gallium/state_trackers/clover/core/format.cpp +++ b/src/gallium/state_trackers/clover/core/format.cpp @@ -145,7 +145,7 @@ namespace clover { } std::set<cl_image_format> - supported_formats(cl_context ctx, cl_mem_object_type type) { + supported_formats(const context &ctx, cl_mem_object_type type) { std::set<cl_image_format> s; pipe_texture_target target = translate_target(type); unsigned bindings = (PIPE_BIND_SAMPLER_VIEW | @@ -154,7 +154,7 @@ namespace clover { PIPE_BIND_TRANSFER_WRITE); for (auto f : formats) { - if (std::all_of(ctx->devs.begin(), ctx->devs.end(), + if (std::all_of(ctx.devs.begin(), ctx.devs.end(), [=](const device *dev) { return dev->pipe->is_format_supported( dev->pipe, f.second, target, 1, bindings); diff --git a/src/gallium/state_trackers/clover/core/format.hpp b/src/gallium/state_trackers/clover/core/format.hpp index dd4e7a544f7..26439c7a93c 100644 --- a/src/gallium/state_trackers/clover/core/format.hpp +++ b/src/gallium/state_trackers/clover/core/format.hpp @@ -37,7 +37,7 @@ namespace clover { /// Return all the image formats supported by a given context for /// the given memory object type. /// - std::set<cl_image_format> supported_formats(cl_context ctx, + std::set<cl_image_format> supported_formats(const context &ctx, cl_mem_object_type type); } diff --git a/src/gallium/state_trackers/clover/core/object.hpp b/src/gallium/state_trackers/clover/core/object.hpp index a4ffb68bd73..101f617ce51 100644 --- a/src/gallium/state_trackers/clover/core/object.hpp +++ b/src/gallium/state_trackers/clover/core/object.hpp @@ -179,6 +179,9 @@ namespace clover { } } +struct _cl_context : + public clover::descriptor<clover::context, _cl_context> {}; + struct _cl_device_id : public clover::descriptor<clover::device, _cl_device_id> {}; |