<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jun 11, 2018 at 10:39 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>
v5:<br>
        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>
        Remove spurious MM_PER_PIXEL define<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>
fixup<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 +++++++++++++++++++++++++<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 f22e727553f..5f6cd96825b 100644<br>
--- a/src/intel/Makefile.sources<br>
+++ b/src/intel/Makefile.sources<br>
@@ -254,6 +254,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 4125cb205ad..9b7fbb74007 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>
@@ -192,6 +192,13 @@ VULKAN_SOURCES += $(VULKAN_WSI_WAYLAND_FILES)<br>
 VULKAN_LIB_DEPS += $(WAYLAND_CLIENT_LIBS)<br>
 endif<br>
<br>
+if HAVE_PLATFORM_DRM<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 56e91fe5de1..b3c6d1a8722 100644<br>
--- a/src/intel/vulkan/anv_device.<wbr>c<br>
+++ b/src/intel/vulkan/anv_device.<wbr>c<br>
@@ -274,6 +274,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>
@@ -445,6 +446,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></blockquote><div><br></div><div>Is this supposed to be opening primary_path instead?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      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></blockquote><div><br></div><div>This could just be</div><div><br></div><div>if (anv_gem_get_param(master_fd, I915_PARAM_CHIPSET_ID) == 0) {</div><div>   close(master_fd);</div><div>   master_fd = -1;<br></div><div>}</div><div><br></div><div>No need to type out all that IOCTL stuff.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      }<br>
+   }<br>
+<br>
    device->local_fd = fd;<br>
    device->master_fd = master_fd;<br>
    return VK_SUCCESS;<br>
@@ -635,6 +655,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 8160864685f..83c09a46741 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 5ea82204eea..83cbfed82c7 100644<br>
--- a/src/intel/vulkan/anv_<wbr>extensions_gen.py<br>
+++ b/src/intel/vulkan/anv_<wbr>extensions_gen.py<br>
@@ -103,7 +103,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>
@@ -122,7 +122,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..877b506b924<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>
+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(<br>
+      physical_device,<br>
+      &pdevice->wsi_device,<br>
+      property_count,<br>
+      properties);<br>
+}<br>
+<br>
+VkResult<br>
+anv_<wbr>GetPhysicalDeviceDisplayPlaneP<wbr>ropertiesKHR(<br>
+   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(<br>
+      physical_device, &pdevice->wsi_device,<br>
+      property_count, 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>
+}<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(<br>
+   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 f20a8a54c9b..86053ff099c 100644<br>
--- a/src/intel/vulkan/meson.build<br>
+++ b/src/intel/vulkan/meson.build<br>
@@ -164,6 +164,11 @@ if with_platform_wayland<br>
   libanv_files += files('anv_wsi_wayland.c')<br>
 endif<br>
<br>
+if with_platform_drm<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.17.1<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>