<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jan 19, 2018 at 3:36 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">v2: add ANV_CONTEXT_REALTIME_PRIORITY (Chris)<br>
    use unreachable with unknown priority (Samuel)<br>
<span class=""><br>
Signed-off-by: Tapani Pälli <<a href="mailto:tapani.palli@intel.com">tapani.palli@intel.com</a>><br>
---<br>
<br>
Small crucible test available here:<br>
<a href="https://cgit.freedesktop.org/~tpalli/crucible/commit/?h=VK_EXT_global_priority" rel="noreferrer" target="_blank">https://cgit.freedesktop.org/~<wbr>tpalli/crucible/commit/?h=VK_<wbr>EXT_global_priority</a><br>
<br>
 src/intel/vulkan/anv_device.c      | 25 +++++++++++++++++++<br>
 src/intel/vulkan/anv_<wbr>extensions.py |  2 ++<br>
</span> src/intel/vulkan/anv_gem.c         | 50 ++++++++++++++++++++++++++++++<wbr>++++++++<br>
 src/intel/vulkan/anv_private.h     | 14 +++++++++++<br>
 4 files changed, 91 insertions(+)<br>
<div><div class="h5"><br>
diff --git a/src/intel/vulkan/anv_device.<wbr>c b/src/intel/vulkan/anv_device.<wbr>c<br>
index 777abd8757..42ebc19f2b 100644<br>
--- a/src/intel/vulkan/anv_device.<wbr>c<br>
+++ b/src/intel/vulkan/anv_device.<wbr>c<br>
@@ -369,6 +369,9 @@ anv_physical_device_init(<wbr>struct anv_physical_device *device,<br>
    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>
@@ -1205,6 +1208,15 @@ VkResult anv_CreateDevice(<br>
       }<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>
@@ -1234,6 +1246,19 @@ VkResult anv_CreateDevice(<br>
       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 = anv_gem_set_context_priority(<wbr>device, priority);<br>
+      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>
index adfebca985..aacf39248f 100644<br>
--- 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>
</div></div>index 34c0989108..59732f191f 100644<br>
--- a/src/intel/vulkan/anv_gem.c<br>
+++ b/src/intel/vulkan/anv_gem.c<br>
@@ -302,6 +302,56 @@ close_and_return:<br>
<span class="">    return swizzled;<br>
 }<br>
<br>
+static int<br>
+vk_priority_to_anv(int priority)<br>
+{<br>
+   switch (priority) {<br>
+   case VK_QUEUE_GLOBAL_PRIORITY_LOW_<wbr>EXT:<br>
+      return ANV_CONTEXT_LOW_PRIORITY;<br>
+   case VK_QUEUE_GLOBAL_PRIORITY_<wbr>MEDIUM_EXT:<br>
+      return ANV_CONTEXT_MEDIUM_PRIORITY;<br>
+   case VK_QUEUE_GLOBAL_PRIORITY_HIGH_<wbr>EXT:<br>
+      return ANV_CONTEXT_HIGH_PRIORITY;<br>
+   case VK_QUEUE_GLOBAL_PRIORITY_<wbr>REALTIME_EXT:<br>
</span>+      return ANV_CONTEXT_REALTIME_PRIORITY;<br>
+   default:<br>
+      unreachable("Invalid priority");<br>
<div><div class="h5">+   }<br>
+}<br>
+<br>
+static int<br>
+_anv_gem_set_context_<wbr>priority(int fd,<br>
+                              int context_id,<br>
+                              int priority)<br>
+{<br>
+   struct drm_i915_gem_context_param p = {<br>
+      .ctx_id = context_id,<br>
+      .param = I915_CONTEXT_PARAM_PRIORITY,<br>
+      .value = vk_priority_to_anv(priority),<br>
+   };<br>
+   int err = 0;<br>
+<br>
+   if (anv_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_<wbr>SETPARAM, &p))<br>
+      err = -errno;<br>
+<br>
+   return err;<br>
+}<br>
+<br>
+int<br>
+anv_gem_set_context_priority(<wbr>struct anv_device *device,<br>
+                             int priority)<br>
+{<br>
+   return _anv_gem_set_context_priority(<wbr>device->fd, device->context_id,<br>
+                                        priority);<br>
+}<br>
+<br>
+bool<br>
+anv_gem_has_context_priority(<wbr>int fd)<br>
+{<br>
+   return !_anv_gem_set_context_<wbr>priority(fd, 0,<br>
+                                         VK_QUEUE_GLOBAL_PRIORITY_<wbr>MEDIUM_EXT);<br>
+}<br>
+<br>
 int<br>
 anv_gem_create_context(struct anv_device *device)<br>
 {<br>
diff --git a/src/intel/vulkan/anv_<wbr>private.h b/src/intel/vulkan/anv_<wbr>private.h<br>
</div></div>index ed711e9434..c24528fade 100644<br>
--- a/src/intel/vulkan/anv_<wbr>private.h<br>
+++ b/src/intel/vulkan/anv_<wbr>private.h<br>
@@ -106,6 +106,17 @@ struct gen_l3_config;<br>
<span class=""> #define ANV_SVGS_VB_INDEX    MAX_VBS<br>
 #define ANV_DRAWID_VB_INDEX (MAX_VBS + 1)<br>
<br>
+#define ANV_CONTEXT_LOW_PRIORITY ((I915_CONTEXT_MIN_USER_<wbr>PRIORITY-1)/2)<br>
+#define ANV_CONTEXT_MEDIUM_PRIORITY (I915_CONTEXT_DEFAULT_<wbr>PRIORITY)<br>
+#define ANV_CONTEXT_HIGH_PRIORITY ((I915_CONTEXT_MAX_USER_<wbr>PRIORITY+1)/2)<br>
</span>+/* We don't have a strict notion of RT (yet, and when we do it is likely<br>
+ * to be more complicated than a mere priority value!), but we can give<br>
+ * it the absolute most priority available to us. By convention, this<br>
+ * is higher than any other client, except for blocked interactive<br>
+ * clients.<br>
+ */<br>
+#define ANV_CONTEXT_REALTIME_PRIORITY I915_CONTEXT_MAX_USER_PRIORITY<br></blockquote><div><br></div><div>I don't see a whole lot of benefit to having these as #defines when all we do with them is put them in a function with a switch statement.</div><div><br></div><div>That said... I see what you mean about sharing with GL.  It would be bad if Vulkan and EGL didn't match.  That would mean that there would be one case where one of the APIs was guaranteed to win.<br></div><div> </div><div>Other than that, it looks good to me.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">+<br>
 #define anv_printflike(a, b) __attribute__((__format__(__<wbr>printf__, a, b)))<br>
<br>
 static inline uint32_t<br>
</span>@@ -768,6 +779,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>
     uint32_t                                    eu_total;<br>
     uint32_t                                    subslice_total;<br>
</span>@@ -914,6 +926,8 @@ int anv_gem_execbuffer(struct anv_device *device,<br>
<div class="HOEnZb"><div class="h5"> 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>
 int anv_gem_get_context_param(int fd, int context, uint32_t param,<br>
                               uint64_t *value);<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
2.14.3<br>
<br>
</font></span></blockquote></div><br></div></div>