summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/clover/api
diff options
context:
space:
mode:
authorTom Stellard <[email protected]>2014-10-21 10:31:56 -0400
committerTom Stellard <[email protected]>2014-10-31 15:24:00 -0400
commite5468dfa523be2a7a0d04bb9efcf8ae780957563 (patch)
treef63800b7dab9a3724092f5761d508ea996c73c79 /src/gallium/state_trackers/clover/api
parent1f4e48d5b53e73605832971f3fb06cb3402f97a5 (diff)
clover: Factor input validation of clCompileProgram into a new function v2
This factors out the validation that is common with clBuildProgram(). v2: - Code cleanups. Reviewed-by: Francisco Jerez <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/clover/api')
-rw-r--r--src/gallium/state_trackers/clover/api/program.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp
index a8a6291806e..e32312eec1b 100644
--- a/src/gallium/state_trackers/clover/api/program.cpp
+++ b/src/gallium/state_trackers/clover/api/program.cpp
@@ -25,6 +25,25 @@
using namespace clover;
+namespace {
+ void validate_build_program_common(const program &prog, cl_uint num_devs,
+ const ref_vector<device> &devs,
+ void (*pfn_notify)(cl_program, void *),
+ void *user_data) {
+
+ if ((!pfn_notify && user_data))
+ throw error(CL_INVALID_VALUE);
+
+ if (prog.kernel_ref_count())
+ throw error(CL_INVALID_OPERATION);
+
+ if (any_of([&](const device &dev) {
+ return !count(dev, prog.context().devices());
+ }, devs))
+ throw error(CL_INVALID_DEVICE);
+ }
+}
+
CLOVER_API cl_program
clCreateProgramWithSource(cl_context d_ctx, cl_uint count,
const char **strings, const size_t *lengths,
@@ -173,18 +192,12 @@ clCompileProgram(cl_program d_prog, cl_uint num_devs,
auto opts = (p_opts ? p_opts : "");
header_map headers;
- if (bool(num_devs) != bool(d_devs) ||
- (!pfn_notify && user_data) ||
- bool(num_headers) != bool(header_names))
- throw error(CL_INVALID_VALUE);
+ validate_build_program_common(prog, num_devs, devs, pfn_notify, user_data);
- if (any_of([&](const device &dev) {
- return !count(dev, prog.context().devices());
- }, devs))
- throw error(CL_INVALID_DEVICE);
+ if (bool(num_headers) != bool(header_names))
+ throw error(CL_INVALID_VALUE);
- if (prog.kernel_ref_count() ||
- !prog.has_source)
+ if (!prog.has_source)
throw error(CL_INVALID_OPERATION);