diff options
Diffstat (limited to 'src/gallium/state_trackers/clover/api')
-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 |
6 files changed, 64 insertions, 77 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); |