<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 7, 2018 at 11:25 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 adds support for the KHR_display extension to the anv Vulkan<br>
driver. The driver now attempts to open the master DRM node when the<br>
KHR_display extension is requested so that the common winsys code can<br>
perform the necessary operations.<br>
<br>
v2: Make sure primary fd is usable<br>
<br>
        When KHR_display is selected, we try to open the primary node<br>
        instead of the render node in case the user wants to use<br>
        KHR_display for presentation. However, if we're actually going<br>
        to end up using RandR leases, then we don't care if the<br>
        resulting fd can't be used for display, but the kernel also<br>
        prevents us from using it for drawing when someone else has<br>
        master.<br>
<br>
v3:<br>
        Simplify addition of VK_USE_PLATFORM_DISPLAY_KHR to vulkan_wsi_args<br>
<br>
        Suggested-by: Eric Engestrom <<a href="mailto:eric.engestrom@imgtec.com">eric.engestrom@imgtec.com</a>><br>
<br>
v4:<br>
        Adapt primary node usage to new wsi_device_init API<br>
<br>
Signed-off-by: Keith Packard <<a href="mailto:keithp@keithp.com">keithp@keithp.com</a>><br>
---<br>
 src/intel/Makefile.sources             |   3 +<br>
 src/intel/<a href="http://Makefile.vulkan.am" rel="noreferrer" target="_blank">Makefile.vulkan.am</a>           |   7 ++<br>
 src/intel/vulkan/anv_device.c          |  21 ++++++<br>
 src/intel/vulkan/anv_<wbr>extensions.py     |   1 +<br>
 src/intel/vulkan/anv_<wbr>extensions_gen.py |   5 +-<br>
 src/intel/vulkan/anv_wsi_<wbr>display.c     | 129 ++++++++++++++++++++++++++++++<wbr>+++<br>
 src/intel/vulkan/meson.build           |   5 ++<br>
 7 files changed, 169 insertions(+), 2 deletions(-)<br>
 create mode 100644 src/intel/vulkan/anv_wsi_<wbr>display.c<br>
<br>
diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources<br>
index 91c71a8dfaf..6c6b57c603d 100644<br>
--- a/src/intel/Makefile.sources<br>
+++ b/src/intel/Makefile.sources<br>
@@ -250,6 +250,9 @@ VULKAN_WSI_WAYLAND_FILES := \<br>
 VULKAN_WSI_X11_FILES := \<br>
        vulkan/anv_wsi_x11.c<br>
<br>
+VULKAN_WSI_DISPLAY_FILES := \<br>
+       vulkan/anv_wsi_display.c<br>
+<br>
 VULKAN_GEM_FILES := \<br>
        vulkan/anv_gem.c<br>
<br>
diff --git a/src/intel/<a href="http://Makefile.vulkan.am" rel="noreferrer" target="_blank">Makefile.vulkan.am</a> b/src/intel/<a href="http://Makefile.vulkan.am" rel="noreferrer" target="_blank">Makefile.vulkan.am</a><br>
index 6b71df6319a..9b6b68abef9 100644<br>
--- a/src/intel/<a href="http://Makefile.vulkan.am" rel="noreferrer" target="_blank">Makefile.vulkan.am</a><br>
+++ b/src/intel/<a href="http://Makefile.vulkan.am" rel="noreferrer" target="_blank">Makefile.vulkan.am</a><br>
@@ -193,6 +193,13 @@ VULKAN_SOURCES += $(VULKAN_WSI_WAYLAND_FILES)<br>
 VULKAN_LIB_DEPS += $(WAYLAND_CLIENT_LIBS)<br>
 endif<br>
<br>
+if HAVE_PLATFORM_DISPLAY<br>
+VULKAN_CPPFLAGS += \<br>
+       -DVK_USE_PLATFORM_DISPLAY_KHR<br>
+<br>
+VULKAN_SOURCES += $(VULKAN_WSI_DISPLAY_FILES)<br>
+endif<br>
+<br>
 noinst_LTLIBRARIES += vulkan/<a href="http://libvulkan_common.la" rel="noreferrer" target="_blank">libvulkan_common.la</a><br>
 vulkan_libvulkan_common_la_<wbr>SOURCES = $(VULKAN_SOURCES)<br>
 vulkan_libvulkan_common_la_<wbr>CFLAGS = $(VULKAN_CFLAGS)<br>
diff --git a/src/intel/vulkan/anv_device.<wbr>c b/src/intel/vulkan/anv_device.<wbr>c<br>
index ab61e0ce339..de1d5af2137 100644<br>
--- a/src/intel/vulkan/anv_device.<wbr>c<br>
+++ b/src/intel/vulkan/anv_device.<wbr>c<br>
@@ -278,6 +278,7 @@ anv_physical_device_init_<wbr>uuids(struct anv_physical_device *device)<br>
 static VkResult<br>
 anv_physical_device_init(<wbr>struct anv_physical_device *device,<br>
                          struct anv_instance *instance,<br>
+                         const char *primary_path,<br>
                          const char *path)<br>
 {<br>
    VkResult result;<br>
@@ -444,6 +445,25 @@ anv_physical_device_init(<wbr>struct anv_physical_device *device,<br>
    anv_physical_device_get_<wbr>supported_extensions(device,<br>
                                                 &device->supported_extensions)<wbr>;<br>
<br>
+   if (instance->enabled_extensions.<wbr>KHR_display) {<br>
+      master_fd = open(path, O_RDWR | O_CLOEXEC);<br>
+      if (master_fd >= 0) {<br>
+         /* prod the device with a GETPARAM call which will fail if<br>
+          * we don't have permission to even render on this device<br>
+          */<br>
+         drm_i915_getparam_t gp;<br>
+         memset(&gp, '\0', sizeof(gp));<br>
+         int devid = 0;<br>
+         gp.param = I915_PARAM_CHIPSET_ID;<br>
+         gp.value = &devid;<br>
+         int ret = drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);<br>
+         if (ret < 0) {<br>
+            close(master_fd);<br>
+            master_fd = -1;<br>
+         }<br>
+      }<br>
+   }<br>
+<br>
    device->local_fd = fd;<br>
    device->master_fd = master_fd;<br>
    return VK_SUCCESS;<br>
@@ -641,6 +661,7 @@ anv_enumerate_devices(struct anv_instance *instance)<br>
<br>
          result = anv_physical_device_init(&<wbr>instance->physicalDevice,<br>
                         instance,<br>
+                        devices[i]->nodes[DRM_NODE_<wbr>PRIMARY],<br>
                         devices[i]->nodes[DRM_NODE_<wbr>RENDER]);<br>
          if (result != VK_ERROR_INCOMPATIBLE_DRIVER)<br>
             break;<br>
diff --git a/src/intel/vulkan/anv_<wbr>extensions.py b/src/intel/vulkan/anv_<wbr>extensions.py<br>
index d0b70a04055..c23c0a87bb9 100644<br>
--- a/src/intel/vulkan/anv_<wbr>extensions.py<br>
+++ b/src/intel/vulkan/anv_<wbr>extensions.py<br>
@@ -107,6 +107,7 @@ EXTENSIONS = [<br>
     Extension('VK_KHR_xcb_surface'<wbr>,                       6, 'VK_USE_PLATFORM_XCB_KHR'),<br>
     Extension('VK_KHR_xlib_<wbr>surface',                      6, 'VK_USE_PLATFORM_XLIB_KHR'),<br>
     Extension('VK_KHR_multiview',                         1, True),<br>
+    Extension('VK_KHR_display',                          23, 'VK_USE_PLATFORM_DISPLAY_KHR')<wbr>,<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>
diff --git a/src/intel/vulkan/anv_<wbr>extensions_gen.py b/src/intel/vulkan/anv_<wbr>extensions_gen.py<br>
index 9bcb631b124..180e6842357 100644<br>
--- a/src/intel/vulkan/anv_<wbr>extensions_gen.py<br>
+++ b/src/intel/vulkan/anv_<wbr>extensions_gen.py<br>
@@ -113,7 +113,7 @@ _TEMPLATE_C = Template(COPYRIGHT + """<br>
 #include "vk_util.h"<br>
<br>
 /* Convert the VK_USE_PLATFORM_* defines to booleans */<br>
-%for platform in ['ANDROID', 'WAYLAND', 'XCB', 'XLIB']:<br>
+%for platform in ['ANDROID', 'WAYLAND', 'XCB', 'XLIB', 'DISPLAY']:<br>
 #ifdef VK_USE_PLATFORM_${platform}_<wbr>KHR<br>
 #   undef VK_USE_PLATFORM_${platform}_<wbr>KHR<br>
 #   define VK_USE_PLATFORM_${platform}_<wbr>KHR true<br>
@@ -132,7 +132,8 @@ _TEMPLATE_C = Template(COPYRIGHT + """<br>
<br>
 #define ANV_HAS_SURFACE (VK_USE_PLATFORM_WAYLAND_KHR || \\<br>
                          VK_USE_PLATFORM_XCB_KHR || \\<br>
-                         VK_USE_PLATFORM_XLIB_KHR)<br>
+                         VK_USE_PLATFORM_XLIB_KHR || \\<br>
+                         VK_USE_PLATFORM_DISPLAY_KHR)<br>
<br>
 static const uint32_t MAX_API_VERSION = ${MAX_API_VERSION.c_vk_<wbr>version()};<br>
<br>
diff --git a/src/intel/vulkan/anv_wsi_<wbr>display.c b/src/intel/vulkan/anv_wsi_<wbr>display.c<br>
new file mode 100644<br>
index 00000000000..9b00d7f02e4<br>
--- /dev/null<br>
+++ b/src/intel/vulkan/anv_wsi_<wbr>display.c<br>
@@ -0,0 +1,129 @@<br>
+/*<br>
+ * Copyright © 2017 Keith Packard<br>
+ *<br>
+ * Permission to use, copy, modify, distribute, and sell this software and its<br>
+ * documentation for any purpose is hereby granted without fee, provided that<br>
+ * the above copyright notice appear in all copies and that both that copyright<br>
+ * notice and this permission notice appear in supporting documentation, and<br>
+ * that the name of the copyright holders not be used in advertising or<br>
+ * publicity pertaining to distribution of the software without specific,<br>
+ * written prior permission.  The copyright holders make no representations<br>
+ * about the suitability of this software for any purpose.  It is provided "as<br>
+ * is" without express or implied warranty.<br>
+ *<br>
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,<br>
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO<br>
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR<br>
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,<br>
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER<br>
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE<br>
+ * OF THIS SOFTWARE.<br>
+ */<br>
+<br>
+#include "anv_private.h"<br>
+#include "wsi_common.h"<br>
+#include "vk_format_info.h"<br>
+#include "vk_util.h"<br>
+#include "wsi_common_display.h"<br>
+<br>
+#define MM_PER_PIXEL     (1.0/96.0 * 25.4)<br></blockquote><div><br></div><div>I don't think you need this. :-)<br><br></div><div>Other than that and the comment on patch 1 about stuff that should probably go here, this 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">
+VkResult<br>
+anv_<wbr>GetPhysicalDeviceDisplayProper<wbr>tiesKHR(VkPhysicalDevice             physical_device,<br>
+                                           uint32_t                     *property_count,<br>
+                                           VkDisplayPropertiesKHR       *properties)<br>
+{<br>
+   ANV_FROM_HANDLE(anv_physical_<wbr>device, pdevice, physical_device);<br>
+<br>
+   return wsi_display_get_physical_<wbr>device_display_properties(<wbr>physical_device,<br>
+                                                             &pdevice->wsi_device,<br>
+                                                             property_count,<br>
+                                                             properties);<br>
+}<br>
+<br>
+VkResult<br>
+anv_<wbr>GetPhysicalDeviceDisplayPlaneP<wbr>ropertiesKHR(VkPhysicalDevice                physical_device,<br>
+                                                uint32_t                        *property_count,<br>
+                                                VkDisplayPlanePropertiesKHR     *properties)<br>
+{<br>
+   ANV_FROM_HANDLE(anv_physical_<wbr>device, pdevice, physical_device);<br>
+<br>
+   return wsi_display_get_physical_<wbr>device_display_plane_<wbr>properties(physical_device,<br>
+                                                                   &pdevice->wsi_device,<br>
+                                                                   property_count,<br>
+                                                                   properties);<br>
+}<br>
+<br>
+VkResult<br>
+anv_<wbr>GetDisplayPlaneSupportedDispla<wbr>ysKHR(VkPhysicalDevice               physical_device,<br>
+                                         uint32_t                       plane_index,<br>
+                                         uint32_t                       *display_count,<br>
+                                         VkDisplayKHR                   *displays)<br>
+{<br>
+   ANV_FROM_HANDLE(anv_physical_<wbr>device, pdevice, physical_device);<br>
+<br>
+   return wsi_display_get_display_plane_<wbr>supported_displays(physical_<wbr>device,<br>
+                                                           &pdevice->wsi_device,<br>
+                                                           plane_index,<br>
+                                                           display_count,<br>
+                                                           displays);<br>
+}<br>
+<br>
+<br>
+VkResult<br>
+anv_<wbr>GetDisplayModePropertiesKHR(<wbr>VkPhysicalDevice               physical_device,<br>
+                                 VkDisplayKHR                   display,<br>
+                                 uint32_t                       *property_count,<br>
+                                 VkDisplayModePropertiesKHR     *properties)<br>
+{<br>
+   ANV_FROM_HANDLE(anv_physical_<wbr>device, pdevice, physical_device);<br>
+<br>
+   return wsi_display_get_display_mode_<wbr>properties(physical_device,<br>
+                                                  &pdevice->wsi_device,<br>
+                                                  display,<br>
+                                                  property_count,<br>
+                                                  properties);<br>
+}<br>
+<br>
+VkResult<br>
+anv_CreateDisplayModeKHR(<wbr>VkPhysicalDevice                      physical_device,<br>
+                          VkDisplayKHR                          display,<br>
+                          const VkDisplayModeCreateInfoKHR      *create_info,<br>
+                          const VkAllocationCallbacks           *allocator,<br>
+                          VkDisplayModeKHR                      *mode)<br>
+{<br>
+   return VK_ERROR_INITIALIZATION_<wbr>FAILED;<br></blockquote><div><br></div><div>This looks valid though it might be nice to allow adding modes at some point.<br><br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+}<br>
+<br>
+<br>
+VkResult<br>
+anv_<wbr>GetDisplayPlaneCapabilitiesKHR<wbr>(VkPhysicalDevice                    physical_device,<br>
+                                    VkDisplayModeKHR                    mode_khr,<br>
+                                    uint32_t                            plane_index,<br>
+                                    VkDisplayPlaneCapabilitiesKHR       *capabilities)<br>
+{<br>
+   ANV_FROM_HANDLE(anv_physical_<wbr>device, pdevice, physical_device);<br>
+<br>
+   return wsi_get_display_plane_<wbr>capabilities(physical_device,<br>
+                                             &pdevice->wsi_device,<br>
+                                             mode_khr,<br>
+                                             plane_index,<br>
+                                             capabilities);<br>
+}<br>
+<br>
+VkResult<br>
+anv_<wbr>CreateDisplayPlaneSurfaceKHR(<wbr>VkInstance                            _instance,<br>
+                                  const VkDisplaySurfaceCreateInfoKHR   *create_info,<br>
+                                  const VkAllocationCallbacks           *allocator,<br>
+                                  VkSurfaceKHR                          *surface)<br>
+{<br>
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);<br>
+   const VkAllocationCallbacks *alloc;<br>
+<br>
+   if (allocator)<br>
+     alloc = allocator;<br>
+   else<br>
+     alloc = &instance->alloc;<br>
+<br>
+   return wsi_create_display_surface(_<wbr>instance, alloc, create_info, surface);<br>
+}<br>
diff --git a/src/intel/vulkan/meson.build b/src/intel/vulkan/meson.build<br>
index ef50134636e..870d0a5a6c4 100644<br>
--- a/src/intel/vulkan/meson.build<br>
+++ b/src/intel/vulkan/meson.build<br>
@@ -173,6 +173,11 @@ if with_platform_wayland<br>
   libanv_files += files('anv_wsi_wayland.c')<br>
 endif<br>
<br>
+if with_platform_display<br>
+  anv_flags += '-DVK_USE_PLATFORM_DISPLAY_<wbr>KHR'<br>
+  libanv_files += files('anv_wsi_display.c')<br>
+endif<br>
+<br>
 libanv_common = static_library(<br>
   'anv_common',<br>
   [libanv_files, anv_entrypoints, anv_extensions_c, anv_extensions_h],<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.16.2<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>