<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jun 14, 2018 at 7:52 PM, Keith Packard <span dir="ltr"><<a href="mailto:keithp@keithp.com" target="_blank">keithp@keithp.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This extension provides fences and frame count information to direct<br>
display contexts. It uses new kernel ioctls to provide 64-bits of<br>
vblank sequence and nanosecond resolution.<br>
<br>
v2:     Adopt Jason Ekstrand's coding conventions<br>
<br>
        Declare variables at first use, eliminate extra whitespace between<br>
        types and names. Wrap lines to 80 columns.<br>
<br>
        Add extension to list in alphabetical order<br>
<br>
        Suggested-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>
<br>
Signed-off-by: Keith Packard <<a href="mailto:keithp@keithp.com">keithp@keithp.com</a>><br>
---<br>
 src/intel/vulkan/anv_<wbr>extensions.py |  1 +<br>
 src/intel/vulkan/anv_private.h     |  4 ++<br>
 src/intel/vulkan/anv_queue.c       | 22 +++++++<br>
 src/intel/vulkan/anv_wsi_<wbr>display.c | 97 ++++++++++++++++++++++++++++++<br>
 4 files changed, 124 insertions(+)<br>
<br>
diff --git a/src/intel/vulkan/anv_<wbr>extensions.py b/src/intel/vulkan/anv_<wbr>extensions.py<br>
index 68e545a40f8..8c010e9280b 100644<br>
--- a/src/intel/vulkan/anv_<wbr>extensions.py<br>
+++ b/src/intel/vulkan/anv_<wbr>extensions.py<br>
@@ -111,6 +111,7 @@ EXTENSIONS = [<br>
     Extension('VK_EXT_acquire_<wbr>xlib_display',              1, 'VK_USE_PLATFORM_XLIB_XRANDR_<wbr>EXT'),<br>
     Extension('VK_EXT_debug_<wbr>report',                      8, True),<br>
     Extension('VK_EXT_direct_mode_<wbr>display',               1, 'VK_USE_PLATFORM_DISPLAY_KHR')<wbr>,<br>
+    Extension('VK_EXT_display_<wbr>control',                   1, 'VK_USE_PLATFORM_DISPLAY_KHR')<wbr>,<br>
     Extension('VK_EXT_display_<wbr>surface_counter',           1, 'VK_USE_PLATFORM_DISPLAY_KHR')<wbr>,<br>
     Extension('VK_EXT_external_<wbr>memory_dma_buf',           1, True),<br>
     Extension('VK_EXT_global_<wbr>priority',                   1,<br>
diff --git a/src/intel/vulkan/anv_<wbr>private.h b/src/intel/vulkan/anv_<wbr>private.h<br>
index fb91bc33046..c81885979ad 100644<br>
--- a/src/intel/vulkan/anv_<wbr>private.h<br>
+++ b/src/intel/vulkan/anv_<wbr>private.h<br>
@@ -2133,6 +2133,7 @@ enum anv_fence_type {<br>
    ANV_FENCE_TYPE_NONE = 0,<br>
    ANV_FENCE_TYPE_BO,<br>
    ANV_FENCE_TYPE_SYNCOBJ,<br>
+   ANV_FENCE_TYPE_WSI,<br>
 };<br>
<br>
 enum anv_bo_fence_state {<br>
@@ -2167,6 +2168,9 @@ struct anv_fence_impl {<br>
<br>
       /** DRM syncobj handle for syncobj-based fences */<br>
       uint32_t syncobj;<br>
+<br>
+      /** WSI fence */<br>
+      struct wsi_fence *fence_wsi;<br>
    };<br>
 };<br>
<br>
diff --git a/src/intel/vulkan/anv_queue.c b/src/intel/vulkan/anv_queue.c<br>
index 8df99c84549..073e65acf5e 100644<br>
--- a/src/intel/vulkan/anv_queue.c<br>
+++ b/src/intel/vulkan/anv_queue.c<br>
@@ -324,6 +324,10 @@ anv_fence_impl_cleanup(struct anv_device *device,<br>
       anv_gem_syncobj_destroy(<wbr>device, impl->syncobj);<br>
       break;<br>
<br>
+   case ANV_FENCE_TYPE_WSI:<br>
+      impl->fence_wsi->destroy(impl-<wbr>>fence_wsi);<br>
+      break;<br>
+<br>
    default:<br>
       unreachable("Invalid fence type");<br>
    }<br>
@@ -672,6 +676,21 @@ done:<br>
    return result;<br>
 }<br>
<br>
+static VkResult<br>
+anv_wait_for_wsi_fence(struct anv_device *device,<br>
+                       const VkFence _fence,<br>
+                       uint64_t abs_timeout)<br>
+{<br>
+   ANV_FROM_HANDLE(anv_fence, fence, _fence);<br>
+<br>
+   struct anv_fence_impl *impl = &fence->permanent;<br>
+   bool expired = impl->fence_wsi->wait(impl-><wbr>fence_wsi, true, abs_timeout);<br>
+<br>
+   if (!expired)<br>
+      return VK_TIMEOUT;<br>
+   return VK_SUCCESS;<br>
+}<br>
+<br>
 static VkResult<br>
 anv_wait_for_fences(struct anv_device *device,<br>
                     uint32_t fenceCount,<br>
@@ -694,6 +713,9 @@ anv_wait_for_fences(struct anv_device *device,<br>
             result = anv_wait_for_syncobj_fences(<wbr>device, 1, &pFences[i],<br>
                                                  true, abs_timeout);<br>
             break;<br>
+         case ANV_FENCE_TYPE_WSI:<br>
+            result = anv_wait_for_wsi_fence(device, pFences[i], abs_timeout);<br>
+            break;<br>
          case ANV_FENCE_TYPE_NONE:<br>
             result = VK_SUCCESS;<br>
             break;<br>
diff --git a/src/intel/vulkan/anv_wsi_<wbr>display.c b/src/intel/vulkan/anv_wsi_<wbr>display.c<br>
index f749a8d98f7..cd736bcdd74 100644<br>
--- a/src/intel/vulkan/anv_wsi_<wbr>display.c<br>
+++ b/src/intel/vulkan/anv_wsi_<wbr>display.c<br>
@@ -168,3 +168,100 @@ anv_GetRandROutputDisplayEXT(<wbr>VkPhysicalDevice  physical_device,<br>
                                        display);<br>
 }<br>
 #endif /* VK_USE_PLATFORM_XLIB_XRANDR_<wbr>EXT */<br>
+<br>
+/* VK_EXT_display_control */<br>
+<br>
+VkResult<br>
+anv_DisplayPowerControlEXT(<wbr>VkDevice                    _device,<br>
+                            VkDisplayKHR                display,<br>
+                            const VkDisplayPowerInfoEXT *display_power_info)<br>
+{<br>
+   ANV_FROM_HANDLE(anv_device, device, _device);<br>
+<br>
+   return wsi_display_power_control(<br>
+      _device, &device->instance-><wbr>physicalDevice.wsi_device,<br>
+      display, display_power_info);<br>
+}<br>
+<br>
+VkResult<br>
+anv_RegisterDeviceEventEXT(<wbr>VkDevice _device,<br>
+                            const VkDeviceEventInfoEXT *device_event_info,<br>
+                            const VkAllocationCallbacks *allocator,<br>
+                            VkFence *_fence)<br>
+{<br>
+   ANV_FROM_HANDLE(anv_device, device, _device);<br>
+   const VkAllocationCallbacks *alloc;<br>
+   struct anv_fence *fence;<br>
+   VkResult ret;<br>
+<br>
+   if (allocator)<br>
+     alloc = allocator;<br>
+   else<br>
+     alloc = &device->instance->alloc;<br></blockquote><div><br></div><div>This is what vk_alloc2 is for. :-)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+   fence = vk_alloc(alloc, sizeof (*fence), 8,<br>
+                    VK_SYSTEM_ALLOCATION_SCOPE_<wbr>OBJECT);<br>
+   if (!fence)<br>
+      return vk_error(VK_ERROR_OUT_OF_HOST_<wbr>MEMORY);<br>
+<br>
+   fence->permanent.type = ANV_FENCE_TYPE_WSI;<br>
+<br>
+   ret = wsi_register_device_event(_<wbr>device,<br>
+                                   &device->instance-><wbr>physicalDevice.wsi_device,<br>
+                                   device_event_info,<br>
+                                   alloc,<br>
+                                   &fence->permanent.fence_wsi);<br>
+   if (ret == VK_SUCCESS)<br>
+      *_fence = anv_fence_to_handle(fence);<br>
+   else<br>
+      vk_free(alloc, fence);</blockquote><div><br></div><div>And vk_free2<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   return ret;<br>
+}<br>
+<br>
+VkResult<br>
+anv_RegisterDisplayEventEXT(<wbr>VkDevice _device,<br>
+                             VkDisplayKHR display,<br>
+                             const VkDisplayEventInfoEXT *display_event_info,<br>
+                             const VkAllocationCallbacks *allocator,<br>
+                             VkFence *_fence)<br>
+{<br>
+   ANV_FROM_HANDLE(anv_device, device, _device);<br>
+   const VkAllocationCallbacks *alloc;<br>
+   struct anv_fence *fence;<br>
+   VkResult ret;<br>
+<br>
+   if (allocator)<br>
+     alloc = allocator;<br>
+   else<br>
+     alloc = &device->instance->alloc;<br></blockquote><div><br></div><div>This isn't needed if you're using vk_alloc2<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+   fence = vk_zalloc2(&device->alloc, allocator, sizeof (*fence), 8,<br>
+                      VK_SYSTEM_ALLOCATION_SCOPE_<wbr>OBJECT);<br></blockquote><div><br></div><div>Above you used vk_alloc and here you're using vk_zalloc.  Mind picking one?  I don't think zalloc is needed but it doesn't hurt so I don't care which.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   if (!fence)<br>
+      return VK_ERROR_OUT_OF_HOST_MEMORY;<br>
+<br>
+   fence->permanent.type = ANV_FENCE_TYPE_WSI;<br>
+<br>
+   ret = wsi_register_display_event(<br>
+      _device, &device->instance-><wbr>physicalDevice.wsi_device,<br>
+      display, display_event_info, alloc, &(fence->permanent.fence_wsi))<wbr>;<br></blockquote><div><br></div><div>Indentation could be consistent between the two functions you add.  I don't care which style.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+   if (ret == VK_SUCCESS)<br>
+      *_fence = anv_fence_to_handle(fence);<br>
+   else<br>
+      vk_free(alloc, fence);<br></blockquote><div><br></div><div>vk_free2?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   return ret;<br>
+}<br>
+<br>
+VkResult<br>
+anv_GetSwapchainCounterEXT(<wbr>VkDevice _device,<br>
+                            VkSwapchainKHR swapchain,<br>
+                            VkSurfaceCounterFlagBitsEXT flag_bits,<br>
+                            uint64_t *value)<br>
+{<br>
+   ANV_FROM_HANDLE(anv_device, device, _device);<br>
+<br>
+   return wsi_get_swapchain_counter(<br>
+      _device, &device->instance-><wbr>physicalDevice.wsi_device,<br>
+      swapchain, flag_bits, value);<br>
+}<br>
<span class="HOEnZb"><font color="#888888">-- <br>
2.17.1<br>
<br>
______________________________<wbr>_________________<br>
dri-devel mailing list<br>
<a href="mailto:dri-devel@lists.freedesktop.org">dri-devel@lists.freedesktop.<wbr>org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/dri-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/dri-devel</a><br>
</font></span></blockquote></div><br></div></div>