[Mesa-dev] [PATCH 1/2 v2] clover: add CL_MEM_HOST_* flags checks

EdB edb+mesa at sigluy.net
Sat Nov 29 06:45:03 PST 2014


those flags have been introduced in OpenCL 1.2
---
 src/gallium/state_trackers/clover/api/memory.cpp   | 15 ++++++++--
 src/gallium/state_trackers/clover/api/transfer.cpp | 32 ++++++++++++++++++++--
 2 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/src/gallium/state_trackers/clover/api/memory.cpp b/src/gallium/state_trackers/clover/api/memory.cpp
index a094e74..fe01d3f 100644
--- a/src/gallium/state_trackers/clover/api/memory.cpp
+++ b/src/gallium/state_trackers/clover/api/memory.cpp
@@ -44,13 +44,18 @@ clCreateBuffer(cl_context d_ctx, cl_mem_flags flags, size_t size,
 
    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))
+                 CL_MEM_COPY_HOST_PTR | CL_MEM_HOST_WRITE_ONLY |
+                 CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS ))
       throw error(CL_INVALID_VALUE);
 
    if (util_bitcount(flags & (CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY |
                               CL_MEM_READ_WRITE)) > 1)
       throw error(CL_INVALID_VALUE);
 
+   if (util_bitcount(flags & (CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY |
+                              CL_MEM_HOST_NO_ACCESS)) > 1)
+      throw error(CL_INVALID_VALUE);
+
    if ((flags & CL_MEM_USE_HOST_PTR) &&
        (flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR)))
       throw error(CL_INVALID_VALUE);
@@ -76,6 +81,11 @@ clCreateSubBuffer(cl_mem d_mem, cl_mem_flags flags,
                                    CL_MEM_WRITE_ONLY)))
       throw error(CL_INVALID_VALUE);
 
+   if (util_bitcount((flags | parent.flags()) &
+                     (CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY |
+                      CL_MEM_HOST_NO_ACCESS)) > 1)
+      throw error(CL_INVALID_VALUE);
+
    if (op == CL_BUFFER_CREATE_TYPE_REGION) {
       auto reg = reinterpret_cast<const cl_buffer_region *>(op_info);
 
@@ -182,7 +192,8 @@ clGetSupportedImageFormats(cl_context d_ctx, cl_mem_flags flags,
 
    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))
+                 CL_MEM_COPY_HOST_PTR | CL_MEM_HOST_WRITE_ONLY |
+                 CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS ))
       throw error(CL_INVALID_VALUE);
 
    if (r_buf && !r_count)
diff --git a/src/gallium/state_trackers/clover/api/transfer.cpp b/src/gallium/state_trackers/clover/api/transfer.cpp
index b8d7771..32bd47a 100644
--- a/src/gallium/state_trackers/clover/api/transfer.cpp
+++ b/src/gallium/state_trackers/clover/api/transfer.cpp
@@ -171,10 +171,30 @@ namespace {
    /// Checks that the mapping flags are correct.
    ///
    void
-   validate_flags(const cl_map_flags flags) {
+   validate_map_flags(const cl_map_flags flags, const cl_mem_flags mem_flags) {
       if ((flags & (CL_MAP_WRITE | CL_MAP_READ)) &&
           (flags & CL_MAP_WRITE_INVALIDATE_REGION))
          throw error(CL_INVALID_VALUE);
+
+      if ((flags & CL_MAP_READ) &&
+          (mem_flags & (CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS)))
+         throw error(CL_INVALID_OPERATION);
+
+      if ((flags & (CL_MAP_WRITE | CL_MAP_WRITE_INVALIDATE_REGION)) &&
+          (mem_flags & (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)))
+         throw error(CL_INVALID_OPERATION);
+   }
+
+   void
+   validate_read_permission(const cl_mem_flags mem_flags) {
+      if (mem_flags & (CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS))
+         throw error(CL_INVALID_OPERATION);
+   }
+
+   void
+   validate_write_permission(const cl_mem_flags mem_flags) {
+      if (mem_flags & (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS))
+         throw error(CL_INVALID_OPERATION);
    }
 
    ///
@@ -269,6 +289,7 @@ clEnqueueReadBuffer(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
    validate_common(q, deps);
    validate_object(q, ptr, {}, obj_pitch, region);
    validate_object(q, mem, obj_origin, obj_pitch, region);
+   validate_read_permission(mem.flags());
 
    auto hev = create<hard_event>(
       q, CL_COMMAND_READ_BUFFER, deps,
@@ -298,6 +319,7 @@ clEnqueueWriteBuffer(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
    validate_common(q, deps);
    validate_object(q, mem, obj_origin, obj_pitch, region);
    validate_object(q, ptr, {}, obj_pitch, region);
+   validate_write_permission(mem.flags());
 
    auto hev = create<hard_event>(
       q, CL_COMMAND_WRITE_BUFFER, deps,
@@ -334,6 +356,7 @@ clEnqueueReadBufferRect(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
    validate_common(q, deps);
    validate_object(q, ptr, host_origin, host_pitch, region);
    validate_object(q, mem, obj_origin, obj_pitch, region);
+   validate_read_permission(mem.flags());
 
    auto hev = create<hard_event>(
       q, CL_COMMAND_READ_BUFFER_RECT, deps,
@@ -370,6 +393,7 @@ clEnqueueWriteBufferRect(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
    validate_common(q, deps);
    validate_object(q, mem, obj_origin, obj_pitch, region);
    validate_object(q, ptr, host_origin, host_pitch, region);
+   validate_write_permission(mem.flags());
 
    auto hev = create<hard_event>(
       q, CL_COMMAND_WRITE_BUFFER_RECT, deps,
@@ -474,6 +498,7 @@ clEnqueueReadImage(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
    validate_common(q, deps);
    validate_object(q, ptr, {}, dst_pitch, region);
    validate_object(q, img, src_origin, region);
+   validate_read_permission(img.flags());
 
    auto hev = create<hard_event>(
       q, CL_COMMAND_READ_IMAGE, deps,
@@ -507,6 +532,7 @@ clEnqueueWriteImage(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
    validate_common(q, deps);
    validate_object(q, img, dst_origin, region);
    validate_object(q, ptr, {}, src_pitch, region);
+   validate_write_permission(img.flags());
 
    auto hev = create<hard_event>(
       q, CL_COMMAND_WRITE_IMAGE, deps,
@@ -639,7 +665,7 @@ clEnqueueMapBuffer(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
 
    validate_common(q, deps);
    validate_object(q, mem, obj_origin, obj_pitch, region);
-   validate_flags(flags);
+   validate_map_flags(flags, mem.flags());
 
    void *map = mem.resource(q).add_map(q, flags, blocking, obj_origin, region);
 
@@ -667,7 +693,7 @@ clEnqueueMapImage(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
 
    validate_common(q, deps);
    validate_object(q, img, origin, region);
-   validate_flags(flags);
+   validate_map_flags(flags, img.flags());
 
    void *map = img.resource(q).add_map(q, flags, blocking, origin, region);
 
-- 
1.9.3



More information about the mesa-dev mailing list