aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/clover/api/context.cpp
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2013-04-06 14:35:00 +0200
committerFrancisco Jerez <[email protected]>2013-04-13 14:20:16 +0200
commit1a8ad6c2e3beb00d07ef109b984658e08c5729da (patch)
tree9daa3310cadfd311ebb92109c131f920419293a8 /src/gallium/state_trackers/clover/api/context.cpp
parent6ace4520559094b755ff1eb038ac68f38faa83c6 (diff)
clover: Define platform class and merge with device_registry.
Null platform IDs are OK according to the spec, but some applications have been reported to get paranoid and assume that our NULL platform is unusable. As it doesn't hurt to have device enumeration separate from the rest of the device code (quite the opposite, it makes the code cleaner), make the API use an actual platform object that keeps track of the available devices instead of the former NULL pointer. Reported-and-reviewed-by: Tom Stellard <[email protected]> Signed-off-by: Francisco Jerez <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/clover/api/context.cpp')
-rw-r--r--src/gallium/state_trackers/clover/api/context.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/gallium/state_trackers/clover/api/context.cpp b/src/gallium/state_trackers/clover/api/context.cpp
index 80afb6bf4ec..99b95666401 100644
--- a/src/gallium/state_trackers/clover/api/context.cpp
+++ b/src/gallium/state_trackers/clover/api/context.cpp
@@ -41,8 +41,7 @@ clCreateContext(const cl_context_properties *props, cl_uint num_devs,
throw error(CL_INVALID_DEVICE);
for (auto p : mprops) {
- if (!(p.first == CL_CONTEXT_PLATFORM &&
- (cl_platform_id)p.second == NULL))
+ if (p.first != CL_CONTEXT_PLATFORM)
throw error(CL_INVALID_PROPERTY);
}
@@ -61,17 +60,25 @@ clCreateContextFromType(const cl_context_properties *props,
cl_device_type type,
void (CL_CALLBACK *pfn_notify)(
const char *, const void *, size_t, void *),
- void *user_data, cl_int *errcode_ret) {
+ void *user_data, cl_int *errcode_ret) try {
+ cl_platform_id platform;
+ cl_uint num_platforms;
cl_device_id dev;
cl_int ret;
- ret = clGetDeviceIDs(0, type, 1, &dev, 0);
- if (ret) {
- ret_error(errcode_ret, ret);
- return NULL;
- }
+ ret = clGetPlatformIDs(1, &platform, &num_platforms);
+ if (ret || !num_platforms)
+ throw error(CL_INVALID_PLATFORM);
+
+ ret = clGetDeviceIDs(platform, type, 1, &dev, 0);
+ if (ret)
+ throw error(CL_DEVICE_NOT_FOUND);
return clCreateContext(props, 1, &dev, pfn_notify, user_data, errcode_ret);
+
+} catch(error &e) {
+ ret_error(errcode_ret, e);
+ return NULL;
}
PUBLIC cl_int