gallium: add PIPE_CAP_RESOURCE_FROM_USER_MEMORY_COMPUTE_ONLY
authorKarol Herbst <kherbst@redhat.com>
Tue, 5 May 2020 13:09:50 +0000 (15:09 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 14 Jul 2020 19:59:12 +0000 (19:59 +0000)
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@redhat.com>
Reviewed-by: Pierre Moreau <dev@pmoreau.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5906>

docs/gallium/screen.rst
src/gallium/auxiliary/util/u_screen.c
src/gallium/frontends/clover/core/device.cpp
src/gallium/frontends/clover/core/device.hpp
src/gallium/frontends/clover/core/resource.cpp
src/gallium/include/pipe/p_defines.h

index 209b978bc14c1ed5fe983af71d09a93206c39b9e..1c572f9af546124e533e110f171b5115960a12e6 100644 (file)
@@ -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``:
index 69e44ab0dcea9220c264525e6ff3ad31d5526cd6..59ff5dc84d57c98eb7482728a89223e529e3324d 100644 (file)
@@ -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:
index ca2d951c76777f4b8c754cf768c845b4767f5c4f..7f3d970ea5fc391741905d1924282fa900b21a15 100644 (file)
@@ -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(),
index 7c8cf13ccf7955c38ea5f184c2c84da9c1c7d558..2cd3a54762e4af87674274557e014a0dfd805961 100644 (file)
@@ -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;
index b8e257db6dc1be2c221a0dc10b6aeddc59a47bf1..c3c6cce5f3bf098bfe9b23a7801ba2d5d8151751 100644 (file)
@@ -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());
index c6a2f0f4f149e04c3466a6c91a621943247d9387..ccb5fa112088acc75c8510f9d93d313cd957d29a 100644 (file)
@@ -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,