clover: Add checks for image support to the image functions v2
authorTom Stellard <thomas.stellard@amd.com>
Fri, 25 Jul 2014 21:12:28 +0000 (17:12 -0400)
committerTom Stellard <thomas.stellard@amd.com>
Mon, 28 Jul 2014 14:10:30 +0000 (10:10 -0400)
Most image functions are required to return a CL_INVALID_OPERATION
error when used on devices without image support.

v2:
  - Simplified the code

Reviewed-by: Francisco Jerez <currojerez@riseup.net>
src/gallium/state_trackers/clover/api/memory.cpp
src/gallium/state_trackers/clover/api/sampler.cpp
src/gallium/state_trackers/clover/api/transfer.cpp

index d26b1c613cb064d0470113c2798c420491bcfa72..a094e74dc67aa6bc4479f5c24e73c9853884eb94 100644 (file)
@@ -106,6 +106,9 @@ clCreateImage2D(cl_context d_ctx, cl_mem_flags flags,
                 void *host_ptr, cl_int *r_errcode) try {
    auto &ctx = obj(d_ctx);
 
+   if (!any_of(std::mem_fn(&device::image_support), ctx.devices()))
+      throw error(CL_INVALID_OPERATION);
+
    if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
                  CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR |
                  CL_MEM_COPY_HOST_PTR))
@@ -141,6 +144,9 @@ clCreateImage3D(cl_context d_ctx, cl_mem_flags flags,
                 void *host_ptr, cl_int *r_errcode) try {
    auto &ctx = obj(d_ctx);
 
+   if (!any_of(std::mem_fn(&device::image_support), ctx.devices()))
+      throw error(CL_INVALID_OPERATION);
+
    if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
                  CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR |
                  CL_MEM_COPY_HOST_PTR))
index 403892b2e608b8cec8defb344b6605cf19e745f6..482e55a9ce94c453f7d425b8da5683132e95fc19 100644 (file)
@@ -31,6 +31,9 @@ clCreateSampler(cl_context d_ctx, cl_bool norm_mode,
                 cl_int *r_errcode) try {
    auto &ctx = obj(d_ctx);
 
+   if (!any_of(std::mem_fn(&device::image_support), ctx.devices()))
+      throw error(CL_INVALID_OPERATION);
+
    ret_error(r_errcode, CL_SUCCESS);
    return new sampler(ctx, norm_mode, addr_mode, filter_mode);
 
index 404ceb028b4bc5af3794b045959b08cffc4542e2..07d8a7307f2db57e84c237fc042a1597b32d2bf7 100644 (file)
@@ -101,6 +101,9 @@ namespace {
                    const vector_t &orig, const vector_t &region) {
       vector_t size = { img.width(), img.height(), img.depth() };
 
+      if (!q.device().image_support())
+         throw error(CL_INVALID_OPERATION);
+
       if (img.context() != q.context())
          throw error(CL_INVALID_CONTEXT);