Mesa (main): clover: Implement CL_MEM_OBJECT_IMAGE1D_ARRAY

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Oct 18 02:55:12 UTC 2021


Module: Mesa
Branch: main
Commit: 786987c4478ea1bdae9ab79a642e0f78c5364948
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=786987c4478ea1bdae9ab79a642e0f78c5364948

Author: Edward O'Callaghan <funfunctor at folklore1984.net>
Date:   Fri Nov 18 17:21:51 2016 +1100

clover: Implement CL_MEM_OBJECT_IMAGE1D_ARRAY

v2: Consider surface height as valid when unused by using 1.
     Fixup width boundary checking.
v3 (Karol): Pull in changes from later commits
            Fix validation

Signed-off-by: Karol Herbst <kherbst at redhat.com>
Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13401>

---

 src/gallium/frontends/clover/api/memory.cpp   | 25 +++++++++++++++++++++----
 src/gallium/frontends/clover/api/transfer.cpp | 10 +++++++++-
 src/gallium/frontends/clover/core/memory.cpp  | 11 +++++++++++
 src/gallium/frontends/clover/core/memory.hpp  | 11 +++++++++++
 4 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/src/gallium/frontends/clover/api/memory.cpp b/src/gallium/frontends/clover/api/memory.cpp
index 014babac6db..f80beff216c 100644
--- a/src/gallium/frontends/clover/api/memory.cpp
+++ b/src/gallium/frontends/clover/api/memory.cpp
@@ -242,6 +242,27 @@ clCreateImageWithProperties(cl_context d_ctx,
                                 desc->image_width,
                                 row_pitch, host_ptr, desc->buffer);
 
+   case CL_MEM_OBJECT_IMAGE1D_ARRAY: {
+      if (!desc->image_width)
+         throw error(CL_INVALID_IMAGE_SIZE);
+
+      if (all_of([=](const device &dev) {
+               const size_t max = dev.max_image_size();
+               const size_t amax = dev.max_image_array_number();
+               return (desc->image_width > max ||
+                       desc->image_array_size > amax);
+            }, ctx.devices()))
+         throw error(CL_INVALID_IMAGE_SIZE);
+
+      const size_t slice_pitch = desc->image_slice_pitch ?
+         desc->image_slice_pitch : row_pitch;
+
+      return new image1d_array(ctx, properties, flags, format,
+                               desc->image_width,
+                               desc->image_array_size, slice_pitch,
+                               host_ptr);
+   }
+
    case CL_MEM_OBJECT_IMAGE2D:
       if (!desc->image_width || !desc->image_height)
          throw error(CL_INVALID_IMAGE_SIZE);
@@ -300,10 +321,6 @@ clCreateImageWithProperties(cl_context d_ctx,
                          slice_pitch, host_ptr);
    }
 
-   case CL_MEM_OBJECT_IMAGE1D_ARRAY:
-      // XXX - Not implemented.
-      throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED);
-
    default:
       throw error(CL_INVALID_IMAGE_DESCRIPTOR);
    }
diff --git a/src/gallium/frontends/clover/api/transfer.cpp b/src/gallium/frontends/clover/api/transfer.cpp
index d802043af00..d279337b3d3 100644
--- a/src/gallium/frontends/clover/api/transfer.cpp
+++ b/src/gallium/frontends/clover/api/transfer.cpp
@@ -104,8 +104,9 @@ namespace {
    void
    validate_object(command_queue &q, image &img,
                    const vector_t &orig, const vector_t &region) {
+      size_t height = img.type() == CL_MEM_OBJECT_IMAGE1D_ARRAY ? img.array_size() : img.height();
       size_t depth = img.type() == CL_MEM_OBJECT_IMAGE2D_ARRAY ? img.array_size() : img.depth();
-      vector_t size = { img.width(), img.height(), depth };
+      vector_t size = { img.width(), height, depth };
       const auto &dev = q.device();
 
       if (!dev.image_support())
@@ -127,6 +128,13 @@ namespace {
             throw error(CL_INVALID_IMAGE_SIZE);
          break;
       }
+      case CL_MEM_OBJECT_IMAGE1D_ARRAY: {
+         const size_t max_size = dev.max_image_size();
+         const size_t max_array = dev.max_image_array_number();
+         if (img.width() > max_size || img.array_size() > max_array)
+            throw error(CL_INVALID_IMAGE_SIZE);
+         break;
+      }
       case CL_MEM_OBJECT_IMAGE2D: {
          const size_t max = dev.max_image_size();
          if (img.width() > max || img.height() > max)
diff --git a/src/gallium/frontends/clover/core/memory.cpp b/src/gallium/frontends/clover/core/memory.cpp
index 6180fcf5d41..6270107e94c 100644
--- a/src/gallium/frontends/clover/core/memory.cpp
+++ b/src/gallium/frontends/clover/core/memory.cpp
@@ -280,6 +280,17 @@ image1d_buffer::image1d_buffer(clover::context &ctx,
                row_pitch, 0, row_pitch, host_ptr, buffer) {
 }
 
+image1d_array::image1d_array(clover::context &ctx,
+                             std::vector<cl_mem_properties> properties,
+                             cl_mem_flags flags,
+                             const cl_image_format *format,
+                             size_t width,
+                             size_t array_size, size_t slice_pitch,
+                             void *host_ptr) :
+   basic_image(ctx, properties, flags, format, width, 1, 1, array_size,
+               0, slice_pitch, slice_pitch * array_size, host_ptr, nullptr) {
+}
+
 image2d::image2d(clover::context &ctx,
                  std::vector<cl_mem_properties> properties,
                  cl_mem_flags flags,
diff --git a/src/gallium/frontends/clover/core/memory.hpp b/src/gallium/frontends/clover/core/memory.hpp
index fa1e53e767f..f05a261332b 100644
--- a/src/gallium/frontends/clover/core/memory.hpp
+++ b/src/gallium/frontends/clover/core/memory.hpp
@@ -205,6 +205,17 @@ namespace clover {
                      void *host_ptr, cl_mem buffer);
    };
 
+   class image1d_array : public basic_image<CL_MEM_OBJECT_IMAGE1D_ARRAY> {
+   public:
+      image1d_array(clover::context &ctx,
+                    std::vector<cl_mem_properties> properties,
+                    cl_mem_flags flags,
+                    const cl_image_format *format,
+                    size_t width,
+                    size_t array_size, size_t slice_pitch,
+                    void *host_ptr);
+   };
+
    class image2d : public basic_image<CL_MEM_OBJECT_IMAGE2D> {
    public:
       image2d(clover::context &ctx,



More information about the mesa-commit mailing list