Mesa (master): gallium: add PIPE_CAP_RESOURCE_FROM_USER_MEMORY_COMPUTE_ONLY

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jul 14 20:20:20 UTC 2020


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

Author: Karol Herbst <kherbst at redhat.com>
Date:   Tue May  5 15:09:50 2020 +0200

gallium: add PIPE_CAP_RESOURCE_FROM_USER_MEMORY_COMPUTE_ONLY

With the current UAPI we only support user pointers from the compute
engines, so we need a way to express that in gallium.

v2: fix typos
v3: add allows_user_pointers helper

Signed-off-by: Karol Herbst <kherbst at redhat.com>
Reviewed-by: Pierre Moreau <dev at pmoreau.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5906>

---

 docs/gallium/screen.rst                        | 3 +++
 src/gallium/auxiliary/util/u_screen.c          | 1 +
 src/gallium/frontends/clover/core/device.cpp   | 9 +++++++--
 src/gallium/frontends/clover/core/device.hpp   | 1 +
 src/gallium/frontends/clover/core/resource.cpp | 4 +---
 src/gallium/include/pipe/p_defines.h           | 1 +
 6 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/docs/gallium/screen.rst b/docs/gallium/screen.rst
index 209b978bc14..1c572f9af54 100644
--- a/docs/gallium/screen.rst
+++ b/docs/gallium/screen.rst
@@ -275,6 +275,9 @@ The integer capabilities:
   existing user memory into the device address space for direct device access.
   The create function is pipe_screen::resource_from_user_memory. The address
   and size must be page-aligned.
+* ``PIPE_CAP_RESOURCE_FROM_USER_MEMORY_COMPUTE_ONLY``: Same as
+  ``PIPE_CAP_RESOURCE_FROM_USER_MEMORY`` but indicates it is only supported from
+  the compute engines.
 * ``PIPE_CAP_DEVICE_RESET_STATUS_QUERY``:
   Whether pipe_context::get_device_reset_status is implemented.
 * ``PIPE_CAP_MAX_SHADER_PATCH_VARYINGS``:
diff --git a/src/gallium/auxiliary/util/u_screen.c b/src/gallium/auxiliary/util/u_screen.c
index 69e44ab0dce..59ff5dc84d5 100644
--- a/src/gallium/auxiliary/util/u_screen.c
+++ b/src/gallium/auxiliary/util/u_screen.c
@@ -214,6 +214,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen,
    case PIPE_CAP_POLYGON_OFFSET_CLAMP:
    case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
    case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
+   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY_COMPUTE_ONLY:
    case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
    case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
    case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
diff --git a/src/gallium/frontends/clover/core/device.cpp b/src/gallium/frontends/clover/core/device.cpp
index ca2d951c767..7f3d970ea5f 100644
--- a/src/gallium/frontends/clover/core/device.cpp
+++ b/src/gallium/frontends/clover/core/device.cpp
@@ -238,8 +238,7 @@ device::svm_support() const {
    //
    // Another unsolvable scenario is a cl_mem object passed by cl_mem reference
    // and SVM pointer into the same kernel at the same time.
-   if (pipe->get_param(pipe, PIPE_CAP_RESOURCE_FROM_USER_MEMORY) &&
-       pipe->get_param(pipe, PIPE_CAP_SYSTEM_SVM))
+   if (allows_user_pointers() && pipe->get_param(pipe, PIPE_CAP_SYSTEM_SVM))
       // we can emulate all lower levels if we support fine grain system
       return CL_DEVICE_SVM_FINE_GRAIN_SYSTEM |
              CL_DEVICE_SVM_COARSE_GRAIN_BUFFER |
@@ -247,6 +246,12 @@ device::svm_support() const {
    return 0;
 }
 
+bool
+device::allows_user_pointers() const {
+   return pipe->get_param(pipe, PIPE_CAP_RESOURCE_FROM_USER_MEMORY) ||
+          pipe->get_param(pipe, PIPE_CAP_RESOURCE_FROM_USER_MEMORY_COMPUTE_ONLY);
+}
+
 std::vector<size_t>
 device::max_block_size() const {
    auto v = get_compute_param<uint64_t>(pipe, ir_format(),
diff --git a/src/gallium/frontends/clover/core/device.hpp b/src/gallium/frontends/clover/core/device.hpp
index 7c8cf13ccf7..2cd3a54762e 100644
--- a/src/gallium/frontends/clover/core/device.hpp
+++ b/src/gallium/frontends/clover/core/device.hpp
@@ -72,6 +72,7 @@ namespace clover {
       bool has_unified_memory() const;
       size_t mem_base_addr_align() const;
       cl_device_svm_capabilities svm_support() const;
+      bool allows_user_pointers() const;
 
       std::vector<size_t> max_block_size() const;
       cl_uint subgroup_size() const;
diff --git a/src/gallium/frontends/clover/core/resource.cpp b/src/gallium/frontends/clover/core/resource.cpp
index b8e257db6dc..c3c6cce5f3b 100644
--- a/src/gallium/frontends/clover/core/resource.cpp
+++ b/src/gallium/frontends/clover/core/resource.cpp
@@ -127,8 +127,6 @@ root_resource::root_resource(clover::device &dev, memory_obj &obj,
                              command_queue &q, const std::string &data) :
    resource(dev, obj) {
    pipe_resource info {};
-   const bool user_ptr_support = dev.pipe->get_param(dev.pipe,
-         PIPE_CAP_RESOURCE_FROM_USER_MEMORY);
 
    if (image *img = dynamic_cast<image *>(&obj)) {
       info.format = translate_format(img->format());
@@ -147,7 +145,7 @@ root_resource::root_resource(clover::device &dev, memory_obj &obj,
                 PIPE_BIND_COMPUTE_RESOURCE |
                 PIPE_BIND_GLOBAL);
 
-   if (obj.flags() & CL_MEM_USE_HOST_PTR && user_ptr_support) {
+   if (obj.flags() & CL_MEM_USE_HOST_PTR && dev.allows_user_pointers()) {
       // Page alignment is normally required for this, just try, hope for the
       // best and fall back if it fails.
       pipe = dev.pipe->resource_from_user_memory(dev.pipe, &info, obj.host_ptr());
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index c6a2f0f4f14..ccb5fa11208 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -811,6 +811,7 @@ enum pipe_cap
    PIPE_CAP_POLYGON_OFFSET_CLAMP,
    PIPE_CAP_MULTISAMPLE_Z_RESOLVE,
    PIPE_CAP_RESOURCE_FROM_USER_MEMORY,
+   PIPE_CAP_RESOURCE_FROM_USER_MEMORY_COMPUTE_ONLY,
    PIPE_CAP_DEVICE_RESET_STATUS_QUERY,
    PIPE_CAP_MAX_SHADER_PATCH_VARYINGS,
    PIPE_CAP_TEXTURE_FLOAT_LINEAR,



More information about the mesa-commit mailing list