[Mesa-dev] [PATCH] clover: Add checks for image support to the image functions v2

Tom Stellard thomas.stellard at amd.com
Fri Jul 25 14:12:28 PDT 2014


Most image functions are required to return a CL_INVALID_OPERATION
error when used on devices without image support.

v2:
  - Simplified the code
---
 src/gallium/state_trackers/clover/api/memory.cpp   | 6 ++++++
 src/gallium/state_trackers/clover/api/sampler.cpp  | 3 +++
 src/gallium/state_trackers/clover/api/transfer.cpp | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/src/gallium/state_trackers/clover/api/memory.cpp b/src/gallium/state_trackers/clover/api/memory.cpp
index d26b1c6..a094e74 100644
--- a/src/gallium/state_trackers/clover/api/memory.cpp
+++ b/src/gallium/state_trackers/clover/api/memory.cpp
@@ -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))
diff --git a/src/gallium/state_trackers/clover/api/sampler.cpp b/src/gallium/state_trackers/clover/api/sampler.cpp
index 403892b..482e55a 100644
--- a/src/gallium/state_trackers/clover/api/sampler.cpp
+++ b/src/gallium/state_trackers/clover/api/sampler.cpp
@@ -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);
 
diff --git a/src/gallium/state_trackers/clover/api/transfer.cpp b/src/gallium/state_trackers/clover/api/transfer.cpp
index 404ceb0..07d8a73 100644
--- a/src/gallium/state_trackers/clover/api/transfer.cpp
+++ b/src/gallium/state_trackers/clover/api/transfer.cpp
@@ -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);
 
-- 
1.8.1.5



More information about the mesa-dev mailing list