<div dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 27, 2018 at 12:14 AM, Tapani Pälli <span dir="ltr"><<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">v2: add ANV_CONTEXT_REALTIME_PRIORITY (Chris)<br>
    use unreachable with unknown priority (Samuel)<br>
<br>
v3: add stubs in gem_stubs.c (Emil)<br>
    use priority defines from gen_defines.h<br>
<br>
</span>v4: cleanup, add anv_gem_set_context_param (Jason)<br>
<br>
Signed-off-by: Tapani Pälli <<a href="mailto:tapani.palli@intel.com">tapani.palli@intel.com</a>><br>
Reviewed-by: Samuel Iglesias Gonsálvez <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>> (v2)<br>
Reviewed-by: Chris Wilson <<a href="mailto:chris@chris-wilson.co.uk">chris@chris-wilson.co.uk</a>> (v2)<br>
Reviewed-by: Emil Velikov <<a href="mailto:emil.velikov@collabora.com">emil.velikov@collabora.com</a>> (v3)<br>
<br>
Signed-off-by: Tapani Pälli <<a href="mailto:tapani.palli@intel.com">tapani.palli@intel.com</a>><br>
---<br>
 src/intel/vulkan/anv_device.c      | 44 ++++++++++++++++++++++++++++++<wbr>++++++++<br>
 src/intel/vulkan/anv_<wbr>extensions.py |  2 ++<br>
 src/intel/vulkan/anv_gem.c         | 32 +++++++++++++++++++++++++++<br>
 src/intel/vulkan/anv_gem_<wbr>stubs.c   | 12 +++++++++++<br>
 src/intel/vulkan/anv_private.h     |  5 +++++<br>
 5 files changed, 95 insertions(+)<br>
<br>
diff --git a/src/intel/vulkan/anv_device.<wbr>c b/src/intel/vulkan/anv_device.<wbr>c<br>
index a83b7a39f6..417969110b 100644<br>
--- a/src/intel/vulkan/anv_device.<wbr>c<br>
+++ b/src/intel/vulkan/anv_device.<wbr>c<br>
@@ -37,6 +37,7 @@<br>
 #include "util/build_id.h"<br>
 #include "util/mesa-sha1.h"<br>
 #include "vk_util.h"<br>
+#include "common/gen_defines.h"<br>
<br>
 #include "genxml/gen7_pack.h"<br>
<br>
@@ -366,6 +367,9 @@ anv_physical_device_init(<wbr>struct anv_physical_device *device,<br>
<span class="">    device->has_syncobj_wait = device->has_syncobj &&<br>
                               anv_gem_supports_syncobj_wait(<wbr>fd);<br>
<br>
+   if (anv_gem_has_context_priority(<wbr>fd))<br>
+      device->has_context_priority = true;<br>
+<br>
    bool swizzled = anv_gem_get_bit6_swizzle(fd, I915_TILING_X);<br>
<br>
    /* Starting with Gen10, the timestamp frequency of the command streamer may<br>
</span>@@ -1316,6 +1320,23 @@ anv_device_init_dispatch(<wbr>struct anv_device *device)<br>
    }<br>
 }<br>
<br>
+static int<br>
+vk_priority_to_gen(int priority)<br>
<span class="">+{<br>
+   switch (priority) {<br>
+   case VK_QUEUE_GLOBAL_PRIORITY_LOW_<wbr>EXT:<br>
+      return GEN_CONTEXT_LOW_PRIORITY;<br>
+   case VK_QUEUE_GLOBAL_PRIORITY_<wbr>MEDIUM_EXT:<br>
+      return GEN_CONTEXT_MEDIUM_PRIORITY;<br>
+   case VK_QUEUE_GLOBAL_PRIORITY_HIGH_<wbr>EXT:<br>
+      return GEN_CONTEXT_HIGH_PRIORITY;<br>
+   case VK_QUEUE_GLOBAL_PRIORITY_<wbr>REALTIME_EXT:<br>
+      return GEN_CONTEXT_REALTIME_PRIORITY;<br>
+   default:<br>
+      unreachable("Invalid priority");<br>
+   }<br>
+}<br>
</span>+<br>
 VkResult anv_CreateDevice(<br>
     VkPhysicalDevice                            physicalDevice,<br>
     const VkDeviceCreateInfo*                   pCreateInfo,<br>
@@ -1359,6 +1380,15 @@ VkResult anv_CreateDevice(<br>
<span class="">       }<br>
    }<br>
<br>
+   /* Check if client specified queue priority. */<br>
+   const VkDeviceQueueGlobalPriorityCre<wbr>ateInfoEXT *queue_priority =<br>
+      vk_find_struct_const(<wbr>pCreateInfo-><wbr>pQueueCreateInfos[0].pNext,<br>
+                           DEVICE_QUEUE_GLOBAL_PRIORITY_<wbr>CREATE_INFO_EXT);<br>
+<br>
+   VkQueueGlobalPriorityEXT priority =<br>
+      queue_priority ? queue_priority->globalPriority :<br>
+         VK_QUEUE_GLOBAL_PRIORITY_<wbr>MEDIUM_EXT;<br>
+<br>
    device = vk_alloc2(&physical_device-><wbr>instance->alloc, pAllocator,<br>
                        sizeof(*device), 8,<br>
                        VK_SYSTEM_ALLOCATION_SCOPE_<wbr>DEVICE);<br>
</span>@@ -1388,6 +1418,20 @@ VkResult anv_CreateDevice(<br>
<span class="">       goto fail_fd;<br>
    }<br>
<br>
+   /* As per spec, the driver implementation may deny requests to acquire<br>
+    * a priority above the default priority (MEDIUM) if the caller does not<br>
+    * have sufficient privileges. In this scenario VK_ERROR_NOT_PERMITTED_EXT<br>
+    * is returned.<br>
+    */<br>
+   if (physical_device->has_context_<wbr>priority) {<br>
+      int err =<br>
</span>+         anv_gem_set_context_priority(<wbr>device, vk_priority_to_gen(priority));<br>
<span class="">+      if (err != 0 && priority > VK_QUEUE_GLOBAL_PRIORITY_<wbr>MEDIUM_EXT) {<br>
+         result = vk_error(VK_ERROR_NOT_<wbr>PERMITTED_EXT);<br>
+         goto fail_fd;<br>
+      }<br>
+   }<br>
+<br>
    device->info = physical_device->info;<br>
    device->isl_dev = physical_device->isl_dev;<br>
<br>
diff --git a/src/intel/vulkan/anv_<wbr>extensions.py b/src/intel/vulkan/anv_<wbr>extensions.py<br>
</span>index 581921e62a..6194eb0ad6 100644<br>
<span class="">--- a/src/intel/vulkan/anv_<wbr>extensions.py<br>
+++ b/src/intel/vulkan/anv_<wbr>extensions.py<br>
@@ -86,6 +86,8 @@ EXTENSIONS = [<br>
     Extension('VK_KHX_multiview',                         1, True),<br>
     Extension('VK_EXT_debug_<wbr>report',                      8, True),<br>
     Extension('VK_EXT_external_<wbr>memory_dma_buf',           1, True),<br>
+    Extension('VK_EXT_global_<wbr>priority',                   1,<br>
+              'device->has_context_priority'<wbr>),<br>
 ]<br>
<br>
 class VkVersion:<br>
diff --git a/src/intel/vulkan/anv_gem.c b/src/intel/vulkan/anv_gem.c<br>
</span>index 34c0989108..93072c7d3b 100644<br>
<span class="">--- a/src/intel/vulkan/anv_gem.c<br>
+++ b/src/intel/vulkan/anv_gem.c<br>
@@ -30,6 +30,7 @@<br>
 #include <fcntl.h><br>
<br>
 #include "anv_private.h"<br>
+#include "common/gen_defines.h"<br>
<br>
 static int<br>
 anv_ioctl(int fd, unsigned long request, void *arg)<br>
</span>@@ -302,6 +303,22 @@ close_and_return:<br>
    return swizzled;<br>
<span class=""> }<br>
<br>
+int<br>
+anv_gem_set_context_priority(<wbr>struct anv_device *device,<br>
+                             int priority)<br>
+{<br>
</span>+   return anv_gem_set_context_param(<wbr>device->fd, device->context_id,<br>
+                                    I915_CONTEXT_PARAM_PRIORITY,<br>
<span class="">+                                    priority);<br>
+}<br>
+<br>
+bool<br>
+anv_gem_has_context_priority(<wbr>int fd)<br>
+{<br>
</span>+   return !anv_gem_set_context_param(fd, 0, I915_CONTEXT_PARAM_PRIORITY,<br>
+                                     GEN_CONTEXT_MEDIUM_PRIORITY);<br>
<span class="">+}<br>
+<br>
 int<br>
 anv_gem_create_context(struct anv_device *device)<br>
 {<br>
</span>@@ -324,6 +341,21 @@ anv_gem_destroy_context(struct anv_device *device, int context)<br>
    return anv_ioctl(device->fd, DRM_IOCTL_I915_GEM_CONTEXT_<wbr>DESTROY, &destroy);<br>
 }<br>
<br>
+int<br>
+anv_gem_set_context_param(int fd, int context, uint32_t param, uint64_t value)<br>
<span class="">+{<br>
+   struct drm_i915_gem_context_param p = {<br>
</span>+      .ctx_id = context,<br>
+      .param = param,<br>
+      .value = value,<br>
<span class="">+   };<br>
+   int err = 0;<br>
+<br>
+   if (anv_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_<wbr>SETPARAM, &p))<br>
+      err = -errno;<br>
</span>+   return err;<br>
+}<br>
+<br>
<span class=""> int<br>
 anv_gem_get_context_param(int fd, int context, uint32_t param, uint64_t *value)<br>
</span> {<br>
diff --git a/src/intel/vulkan/anv_gem_<wbr>stubs.c b/src/intel/vulkan/anv_gem_<wbr>stubs.c<br>
index 26eb5c8a61..0f4a3f5da0 100644<br>
--- a/src/intel/vulkan/anv_gem_<wbr>stubs.c<br>
+++ b/src/intel/vulkan/anv_gem_<wbr>stubs.c<br>
@@ -146,12 +146,24 @@ anv_gem_destroy_context(struct anv_device *device, int context)<br>
    unreachable("Unused");<br>
 }<br>
<br>
+int<br>
+anv_gem_set_context_param(int fd, int context, uint32_t param, uint64_t value)<br>
<span class="">+{<br>
+   unreachable("Unused");<br>
+}<br>
+<br>
 int<br>
</span><span class=""> anv_gem_get_context_param(int fd, int context, uint32_t param, uint64_t *value)<br>
 {<br>
    unreachable("Unused");<br>
 }<br>
<br>
+bool<br>
</span>+anv_gem_has_context_priority(<wbr>int fd)<br>
<span class="">+{<br>
+   unreachable("Unused");<br>
+}<br>
+<br>
</span><span class=""> int<br>
 anv_gem_get_aperture(int fd, uint64_t *size)<br>
 {<br>
diff --git a/src/intel/vulkan/anv_<wbr>private.h b/src/intel/vulkan/anv_<wbr>private.h<br>
</span>index 104b28ee5d..0be815d995 100644<br>
--- a/src/intel/vulkan/anv_<wbr>private.h<br>
+++ b/src/intel/vulkan/anv_<wbr>private.h<br>
@@ -769,6 +769,7 @@ struct anv_physical_device {<br>
<span class="">     bool                                        has_exec_fence;<br>
     bool                                        has_syncobj;<br>
     bool                                        has_syncobj_wait;<br>
+    bool                                        has_context_priority;<br>
<br>
</span>     struct anv_device_extension_table           supported_extensions;<br>
<br>
@@ -921,7 +922,11 @@ int anv_gem_execbuffer(struct anv_device *device,<br>
<span class=""> int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle,<br>
                        uint32_t stride, uint32_t tiling);<br>
 int anv_gem_create_context(struct anv_device *device);<br>
+bool anv_gem_has_context_priority(<wbr>int fd);<br>
+int anv_gem_set_context_priority(<wbr>struct anv_device *device, int priority);<br>
 int anv_gem_destroy_context(struct anv_device *device, int context);<br>
</span>+int anv_gem_set_context_param(int fd, int context, uint32_t param,<br>
+                              uint64_t value);<br>
<span class=""> int anv_gem_get_context_param(int fd, int context, uint32_t param,<br>
                               uint64_t *value);<br>
</span> int anv_gem_get_param(int fd, uint32_t param);<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.14.3<br>
<br>
</font></span></blockquote></div><br></div>