Mesa (main): clover: Implement CL_MEM_OBJECT_IMAGE2D_ARRAY

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


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

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

clover: Implement CL_MEM_OBJECT_IMAGE2D_ARRAY

v2: Ensure we pass in row_pitch state as well.
v3 (Karol): Pull in changes from later commits

Signed-off-by: Edward O'Callaghan <funfunctor at folklore1984.net>
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   | 23 ++++++++++++++++++++++-
 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, 53 insertions(+), 2 deletions(-)

diff --git a/src/gallium/frontends/clover/api/memory.cpp b/src/gallium/frontends/clover/api/memory.cpp
index 4ce0d3c6710..668d86bf6a4 100644
--- a/src/gallium/frontends/clover/api/memory.cpp
+++ b/src/gallium/frontends/clover/api/memory.cpp
@@ -243,6 +243,28 @@ clCreateImageWithProperties(cl_context d_ctx,
                          desc->image_width, desc->image_height,
                          row_pitch, host_ptr);
 
+   case CL_MEM_OBJECT_IMAGE2D_ARRAY: {
+      if (!desc->image_width || !desc->image_height || !desc->image_array_size)
+         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_height > 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 * desc->image_height;
+
+      return new image2d_array(ctx, properties, flags, format,
+                               desc->image_width, desc->image_height,
+                               desc->image_array_size, row_pitch,
+                               slice_pitch, host_ptr);
+   }
+
    case CL_MEM_OBJECT_IMAGE3D: {
       if (!desc->image_width || !desc->image_height || !desc->image_depth)
          throw error(CL_INVALID_IMAGE_SIZE);
@@ -266,7 +288,6 @@ clCreateImageWithProperties(cl_context d_ctx,
 
    case CL_MEM_OBJECT_IMAGE1D_ARRAY:
    case CL_MEM_OBJECT_IMAGE1D_BUFFER:
-   case CL_MEM_OBJECT_IMAGE2D_ARRAY:
       // XXX - Not implemented.
       throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED);
 
diff --git a/src/gallium/frontends/clover/api/transfer.cpp b/src/gallium/frontends/clover/api/transfer.cpp
index fd089fbad47..d802043af00 100644
--- a/src/gallium/frontends/clover/api/transfer.cpp
+++ b/src/gallium/frontends/clover/api/transfer.cpp
@@ -104,7 +104,8 @@ namespace {
    void
    validate_object(command_queue &q, image &img,
                    const vector_t &orig, const vector_t &region) {
-      vector_t size = { img.width(), img.height(), img.depth() };
+      size_t depth = img.type() == CL_MEM_OBJECT_IMAGE2D_ARRAY ? img.array_size() : img.depth();
+      vector_t size = { img.width(), img.height(), depth };
       const auto &dev = q.device();
 
       if (!dev.image_support())
@@ -132,6 +133,13 @@ namespace {
             throw error(CL_INVALID_IMAGE_SIZE);
          break;
       }
+      case CL_MEM_OBJECT_IMAGE2D_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.height() > max_size || img.array_size() > max_array)
+            throw error(CL_INVALID_IMAGE_SIZE);
+         break;
+      }
       case CL_MEM_OBJECT_IMAGE3D: {
          const size_t max = dev.max_image_size_3d();
          if (img.width() > max || img.height() > max || img.depth() > max)
diff --git a/src/gallium/frontends/clover/core/memory.cpp b/src/gallium/frontends/clover/core/memory.cpp
index 251fad26f50..a59972f7953 100644
--- a/src/gallium/frontends/clover/core/memory.cpp
+++ b/src/gallium/frontends/clover/core/memory.cpp
@@ -280,6 +280,17 @@ image2d::image2d(clover::context &ctx,
                row_pitch, 0, height * row_pitch, host_ptr, nullptr) {
 }
 
+image2d_array::image2d_array(clover::context &ctx,
+                             std::vector<cl_mem_properties> properties,
+                             cl_mem_flags flags,
+                             const cl_image_format *format,
+                             size_t width, size_t height, size_t array_size,
+                             size_t row_pitch, size_t slice_pitch,
+                             void *host_ptr) :
+   basic_image(ctx, properties, flags, format, width, height, 1, array_size,
+               row_pitch, slice_pitch, slice_pitch * array_size, host_ptr, nullptr) {
+}
+
 image3d::image3d(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 38cda7ce749..72d9d32d969 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);
    };
 
+   class image2d_array : public basic_image<CL_MEM_OBJECT_IMAGE2D_ARRAY> {
+   public:
+      image2d_array(clover::context &ctx,
+                    std::vector<cl_mem_properties> properties,
+                    cl_mem_flags flags,
+                    const cl_image_format *format,
+                    size_t width, size_t height, size_t array_size,
+                    size_t row_pitch, size_t slice_pitch,
+                    void *host_ptr);
+   };
+
    class image3d : public basic_image<CL_MEM_OBJECT_IMAGE3D>{
    public:
       image3d(clover::context &ctx,



More information about the mesa-commit mailing list