Mesa (main): clover/formats: pass in cl_mem_flags for better format checking

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Oct 18 21:29:03 UTC 2021


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

Author: Karol Herbst <kherbst at redhat.com>
Date:   Wed Oct 21 05:03:27 2020 +0200

clover/formats: pass in cl_mem_flags for better format checking

This allows us to advertise more formats depending on how the image is
getting used inside a kernel.

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/13424>

---

 src/gallium/frontends/clover/api/memory.cpp  |  4 ++--
 src/gallium/frontends/clover/core/device.hpp |  2 +-
 src/gallium/frontends/clover/core/format.cpp | 10 +++++++---
 src/gallium/frontends/clover/core/format.hpp |  3 ++-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/gallium/frontends/clover/api/memory.cpp b/src/gallium/frontends/clover/api/memory.cpp
index 03f1c48b8d6..f3325950518 100644
--- a/src/gallium/frontends/clover/api/memory.cpp
+++ b/src/gallium/frontends/clover/api/memory.cpp
@@ -204,7 +204,7 @@ clCreateImageWithProperties(cl_context d_ctx,
 
    const cl_mem_flags flags = validate_flags(desc->buffer, d_flags, false);
 
-   if (!supported_formats(ctx, desc->image_type).count(*format))
+   if (!supported_formats(ctx, desc->image_type, d_flags).count(*format))
       throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED);
 
    std::vector<cl_mem_properties> properties = fill_properties(d_properties);
@@ -368,7 +368,7 @@ clGetSupportedImageFormats(cl_context d_ctx, cl_mem_flags flags,
                            cl_mem_object_type type, cl_uint count,
                            cl_image_format *r_buf, cl_uint *r_count) try {
    auto &ctx = obj(d_ctx);
-   auto formats = supported_formats(ctx, type);
+   auto formats = supported_formats(ctx, type, flags);
 
    if (flags & CL_MEM_KERNEL_READ_AND_WRITE) {
       if (r_count)
diff --git a/src/gallium/frontends/clover/core/device.hpp b/src/gallium/frontends/clover/core/device.hpp
index ae80bd12e14..4020ae96269 100644
--- a/src/gallium/frontends/clover/core/device.hpp
+++ b/src/gallium/frontends/clover/core/device.hpp
@@ -106,7 +106,7 @@ namespace clover {
       friend class root_resource;
       friend class hard_event;
       friend std::set<cl_image_format>
-      supported_formats(const context &, cl_mem_object_type);
+      supported_formats(const context &, cl_mem_object_type, cl_mem_flags flags);
       const void *get_compiler_options(enum pipe_shader_ir ir) const;
 
       clover::platform &platform;
diff --git a/src/gallium/frontends/clover/core/format.cpp b/src/gallium/frontends/clover/core/format.cpp
index 64ceba7dedf..6a0a2690cfe 100644
--- a/src/gallium/frontends/clover/core/format.cpp
+++ b/src/gallium/frontends/clover/core/format.cpp
@@ -126,11 +126,15 @@ namespace clover {
    }
 
    std::set<cl_image_format>
-   supported_formats(const context &ctx, cl_mem_object_type type) {
+   supported_formats(const context &ctx, cl_mem_object_type type, cl_mem_flags flags) {
       std::set<cl_image_format> s;
       pipe_texture_target target = translate_target(type);
-      unsigned bindings = (PIPE_BIND_SAMPLER_VIEW |
-                           PIPE_BIND_COMPUTE_RESOURCE);
+      unsigned bindings = 0;
+
+      if (flags & (CL_MEM_READ_ONLY | CL_MEM_READ_WRITE | CL_MEM_KERNEL_READ_AND_WRITE))
+         bindings |= PIPE_BIND_SAMPLER_VIEW;
+      if (flags & (CL_MEM_WRITE_ONLY | CL_MEM_READ_WRITE | CL_MEM_KERNEL_READ_AND_WRITE))
+         bindings |= PIPE_BIND_SHADER_IMAGE;
 
       for (auto f : formats) {
          if (all_of([=](const device &dev) {
diff --git a/src/gallium/frontends/clover/core/format.hpp b/src/gallium/frontends/clover/core/format.hpp
index a8b7053c5dc..a66a817e926 100644
--- a/src/gallium/frontends/clover/core/format.hpp
+++ b/src/gallium/frontends/clover/core/format.hpp
@@ -38,7 +38,8 @@ namespace clover {
    /// the given memory object type.
    ///
    std::set<cl_image_format> supported_formats(const context &ctx,
-                                               cl_mem_object_type type);
+                                               cl_mem_object_type type,
+                                               cl_mem_flags flags);
 }
 
 static inline bool



More information about the mesa-commit mailing list