<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Feb 9, 2018 at 8:45 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This adds support for the KHR_display extension to the anv and radv<br>
Vulkan drivers. The drivers now attempt to open the master DRM node<br>
when the KHR_display extension is requested so that the common winsys<br>
code can perform the necessary operations.<br>
<br>
Signed-off-by: Keith Packard <<a href="mailto:keithp@keithp.com" target="_blank">keithp@keithp.com</a>><br>
---<br>
<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> | 1 +<br>
meson.build | 4 +-<br>
src/amd/vulkan/Makefile.am | 8 +<br>
src/amd/vulkan/Makefile.sourc<wbr>es | 3 +<br>
src/amd/vulkan/meson.build | 7 +<br>
src/amd/vulkan/radv_device.c | 28 +-<br>
src/amd/vulkan/radv_extension<wbr>s.py | 7 +-<br>
src/amd/vulkan/radv_private.<wbr>h | 2 +<br>
src/amd/vulkan/radv_wsi.c | 3 +-<br>
src/amd/vulkan/radv_wsi_displ<wbr>ay.c | 143 ++++<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.<wbr>c | 18 +-<br>
src/intel/vulkan/anv_extensio<wbr>ns.py | 1 +<br>
src/intel/vulkan/anv_extensio<wbr>ns_gen.py | 5 +-<br>
src/intel/vulkan/anv_wsi.c | 3 +-<br>
src/intel/vulkan/anv_wsi_disp<wbr>lay.c | 129 +++<br>
src/intel/vulkan/meson.build | 7 +<br>
src/vulkan/Makefile.am | 7 +<br>
src/vulkan/Makefile.sources | 4 +<br>
src/vulkan/wsi/meson.build | 10 +<br>
src/vulkan/wsi/wsi_common.c | 19 +-<br>
src/vulkan/wsi/wsi_common.h | 5 +-<br>
src/vulkan/wsi/wsi_common_dis<wbr>play.c | 1368 ++++++++++++++++++++++++++++++<wbr>++<br>
src/vulkan/wsi/wsi_common_dis<wbr>play.h | 72 ++<br>
src/vulkan/wsi/wsi_common_pri<wbr>vate.h | 10 +<br>
26 files changed, 1858 insertions(+), 16 deletions(-)<br>
create mode 100644 src/amd/vulkan/radv_wsi_displa<wbr>y.c<br>
create mode 100644 src/intel/vulkan/anv_wsi_displ<wbr>ay.c<br>
create mode 100644 src/vulkan/wsi/wsi_common_disp<wbr>lay.c<br>
create mode 100644 src/vulkan/wsi/wsi_common_disp<wbr>lay.h<br>
<br>
diff --git a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
index 8ed606c7694..46318365603 100644<br>
--- a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
+++ b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
@@ -1849,6 +1849,7 @@ fi<br>
AM_CONDITIONAL(HAVE_PLATFORM_<wbr>X11, echo "$platforms" | grep -q 'x11')<br>
AM_CONDITIONAL(HAVE_PLATFORM_<wbr>WAYLAND, echo "$platforms" | grep -q 'wayland')<br>
AM_CONDITIONAL(HAVE_PLATFORM_<wbr>DRM, echo "$platforms" | grep -q 'drm')<br>
+AM_CONDITIONAL(HAVE_PLATFORM_<wbr>DISPLAY, echo "$platforms" | grep -q 'drm')<br>
AM_CONDITIONAL(HAVE_PLATFORM_<wbr>SURFACELESS, echo "$platforms" | grep -q 'surfaceless')<br>
AM_CONDITIONAL(HAVE_PLATFORM_<wbr>ANDROID, echo "$platforms" | grep -q 'android')<br>
<br>
diff --git a/meson.build b/meson.build<br>
index b39e2f8ab96..aeb7f5e2917 100644<br>
--- a/meson.build<br>
+++ b/meson.build<br>
@@ -239,11 +239,12 @@ with_platform_wayland = false<br>
with_platform_x11 = false<br>
with_platform_drm = false<br>
with_platform_surfaceless = false<br>
+with_platform_display = false<br>
egl_native_platform = ''<br>
_platforms = get_option('platforms')<br>
if _platforms == 'auto'<br>
if system_has_kms_drm<br>
- _platforms = 'x11,wayland,drm,surfaceless'<br>
+ _platforms = 'x11,wayland,drm,surfaceless,d<wbr>isplay'<br>
elif ['darwin', 'windows', 'cygwin'].contains(host_machin<wbr>e.system())<br>
_platforms = 'x11,surfaceless'<br>
else<br>
@@ -257,6 +258,7 @@ if _platforms != ''<br>
with_platform_wayland = _split.contains('wayland')<br>
with_platform_drm = _split.contains('drm')<br>
with_platform_surfaceless = _split.contains('surfaceless')<br>
+ with_platform_display = _split.contains('display')<br>
egl_native_platform = _split[0]<br>
endif<br>
<br>
diff --git a/src/amd/vulkan/Makefile.am b/src/amd/vulkan/Makefile.am<br>
index 61025968942..061b8144b88 100644<br>
--- a/src/amd/vulkan/Makefile.am<br>
+++ b/src/amd/vulkan/Makefile.am<br>
@@ -76,6 +76,14 @@ VULKAN_LIB_DEPS = \<br>
$(DLOPEN_LIBS) \<br>
-lm<br>
<br>
+if HAVE_PLATFORM_DISPLAY<br>
+AM_CPPFLAGS += \<br>
+ -DVK_USE_PLATFORM_DISPLAY_KHR<br>
+<br>
+VULKAN_SOURCES += $(VULKAN_WSI_DISPLAY_FILES)<br>
+<br>
+endif<br>
+<br>
if HAVE_PLATFORM_X11<br>
AM_CPPFLAGS += \<br>
$(XCB_DRI3_CFLAGS) \<br>
diff --git a/src/amd/vulkan/Makefile.sour<wbr>ces b/src/amd/vulkan/Makefile.sour<wbr>ces<br>
index a510d88d965..618a6cdaed0 100644<br>
--- a/src/amd/vulkan/Makefile.sour<wbr>ces<br>
+++ b/src/amd/vulkan/Makefile.sour<wbr>ces<br>
@@ -78,6 +78,9 @@ VULKAN_WSI_WAYLAND_FILES := \<br>
VULKAN_WSI_X11_FILES := \<br>
radv_wsi_x11.c<br>
<br>
+VULKAN_WSI_DISPLAY_FILES := \<br>
+ radv_wsi_display.c<br>
+<br>
VULKAN_GENERATED_FILES := \<br>
radv_entrypoints.c \<br>
radv_entrypoints.h \<br>
diff --git a/src/amd/vulkan/meson.build b/src/amd/vulkan/meson.build<br>
index 0a7b7c0bf3c..b7bb1075e7d 100644<br>
--- a/src/amd/vulkan/meson.build<br>
+++ b/src/amd/vulkan/meson.build<br>
@@ -112,6 +112,13 @@ if with_platform_wayland<br>
libradv_files += files('radv_wsi_wayland.c')<br>
endif<br>
<br>
+if with_platform_display<br>
+ radv_flags += [<br>
+ '-DVK_USE_PLATFORM_DISPLAY_KHR<wbr>',<br>
+ ]<br>
+ libradv_files += files('radv_wsi_display.c')<br>
+endif<br>
+<br>
libvulkan_radeon = shared_library(<br>
'vulkan_radeon',<br>
[libradv_files, radv_entrypoints, radv_extensions_c, vk_format_table_c],<br>
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c<br>
index 09bb382eeb8..adf33eb35dc 100644<br>
--- a/src/amd/vulkan/radv_device.c<br>
+++ b/src/amd/vulkan/radv_device.c<br>
@@ -191,9 +191,26 @@ radv_physical_device_init(stru<wbr>ct radv_physical_device *device,<br>
const char *path = drm_device->nodes[DRM_NODE_REN<wbr>DER];<br>
VkResult result;<br>
drmVersionPtr version;<br>
- int fd;<br>
-<br>
- fd = open(path, O_RDWR | O_CLOEXEC);<br>
+ int fd = -1;<br>
+<br>
+ if (instance->khr_display_request<wbr>ed) {<br>
+ fd = open(drm_device->nodes[DRM_NOD<wbr>E_PRIMARY], O_RDWR | O_CLOEXEC);<br>
+ if (fd >= 0) {<br>
+ uint32_t accel_working = 0;<br>
+ struct drm_amdgpu_info request = {<br>
+ .return_pointer = (uintptr_t)&accel_working,<br>
+ .return_size = sizeof(accel_working),<br>
+ .query = AMDGPU_INFO_ACCEL_WORKING<br>
+ };<br>
+<br>
+ if (drmCommandWrite(fd, DRM_AMDGPU_INFO, &request, sizeof (struct drm_amdgpu_info)) < 0 || !accel_working) {<br>
+ close(fd);<br>
+ fd = -1;<br>
+ }<br>
+ }<br>
+ }<br>
+ if (fd < 0)<br>
+ fd = open(path, O_RDWR | O_CLOEXEC);<br>
if (fd < 0)<br>
return vk_error(VK_ERROR_INCOMPATIBLE<wbr>_DRIVER);<br>
<br>
@@ -209,6 +226,7 @@ radv_physical_device_init(stru<wbr>ct radv_physical_device *device,<br>
close(fd);<br>
return VK_ERROR_INCOMPATIBLE_DRIVER;<br>
}<br>
+<br>
drmFreeVersion(version);<br>
<br>
device->_loader_data.loaderMag<wbr>ic = ICD_LOADER_MAGIC;<br>
@@ -387,6 +405,7 @@ VkResult radv_CreateInstance(<br>
{<br>
struct radv_instance *instance;<br>
VkResult result;<br>
+ bool khr_display_requested = false;<br>
<br>
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CRE<wbr>ATE_INFO);<br>
<br>
@@ -411,6 +430,8 @@ VkResult radv_CreateInstance(<br>
const char *ext_name = pCreateInfo->ppEnabledExtensio<wbr>nNames[i];<br>
if (!radv_instance_extension_supp<wbr>orted(ext_name))<br>
return vk_error(VK_ERROR_EXTENSION_NO<wbr>T_PRESENT);<br>
+ if (strcmp(ext_name, VK_KHR_DISPLAY_EXTENSION_NAME) == 0)<br>
+ khr_display_requested = true;<br>
}<br>
<br>
instance = vk_zalloc2(&default_alloc, pAllocator, sizeof(*instance), 8,<br>
@@ -427,6 +448,7 @@ VkResult radv_CreateInstance(<br>
<br>
instance->apiVersion = client_version;<br>
instance->physicalDeviceCount = -1;<br>
+ instance->khr_display_requeste<wbr>d = khr_display_requested;<br>
<br>
result = vk_debug_report_instance_init(<wbr>&instance->debug_report_callba<wbr>cks);<br>
if (result != VK_SUCCESS) {<br>
diff --git a/src/amd/vulkan/radv_extensio<wbr>ns.py b/src/amd/vulkan/radv_extensio<wbr>ns.py<br>
index d761895d3a0..24cab8cbb39 100644<br>
--- a/src/amd/vulkan/radv_extensio<wbr>ns.py<br>
+++ b/src/amd/vulkan/radv_extensio<wbr>ns.py<br>
@@ -81,6 +81,7 @@ EXTENSIONS = [<br>
Extension('VK_KHR_wayland_sur<wbr>face', 6, 'VK_USE_PLATFORM_WAYLAND_KHR')<wbr>,<br>
Extension('VK_KHR_xcb_<wbr>surface', 6, 'VK_USE_PLATFORM_XCB_KHR'),<br>
Extension('VK_KHR_xlib_surfac<wbr>e', 6, 'VK_USE_PLATFORM_XLIB_KHR'),<br>
+ Extension('VK_KHR_display', 1, 'VK_USE_PLATFORM_DISPLAY_KHR')<wbr>,<br>
Extension('VK_KHX_multiview',<wbr> 1, '!ANDROID'),<br>
Extension('VK_EXT_debug_repor<wbr>t', 9, True),<br>
Extension('VK_EXT_discard_rec<wbr>tangles', 1, True),<br>
@@ -168,7 +169,7 @@ _TEMPLATE = 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}_KH<wbr>R<br>
# undef VK_USE_PLATFORM_${platform}_KH<wbr>R<br>
# define VK_USE_PLATFORM_${platform}_KH<wbr>R true<br>
@@ -187,7 +188,9 @@ _TEMPLATE = Template(COPYRIGHT + """<br>
<br>
#define RADV_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>
<br>
bool<br>
radv_instance_extension_suppo<wbr>rted(const char *name)<br>
diff --git a/src/amd/vulkan/radv_private.<wbr>h b/src/amd/vulkan/radv_private.<wbr>h<br>
index be9e8f43964..1e3719bcc4f 100644<br>
--- a/src/amd/vulkan/radv_private.<wbr>h<br>
+++ b/src/amd/vulkan/radv_private.<wbr>h<br>
@@ -75,6 +75,7 @@ typedef uint32_t xcb_window_t;<br>
#include "radv_entrypoints.h"<br>
<br>
#include "wsi_common.h"<br>
+#include "wsi_common_display.h"<br>
<br>
#define ATI_VENDOR_ID 0x1002<br>
<br>
@@ -300,6 +301,7 @@ struct radv_instance {<br>
uint64_t perftest_flags;<br>
<br>
struct vk_debug_report_instance debug_report_callbacks;<br>
+ bool khr_display_requested;<br>
};<br>
<br>
VkResult radv_init_wsi(struct radv_physical_device *physical_device);<br>
diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c<br>
index e016e837102..5ec872a63d0 100644<br>
--- a/src/amd/vulkan/radv_wsi.c<br>
+++ b/src/amd/vulkan/radv_wsi.c<br>
@@ -41,7 +41,8 @@ radv_init_wsi(struct radv_physical_device *physical_device)<br>
return wsi_device_init(&physical_devi<wbr>ce->wsi_device,<br>
radv_physical_device_to_handl<wbr>e(physical_device),<br>
radv_wsi_proc_addr,<br>
- &physical_device->instance->al<wbr>loc);<br>
+ &physical_device->instance->al<wbr>loc,<br>
+ physical_device->local_fd);<br>
}<br>
<br>
void<br>
diff --git a/src/amd/vulkan/radv_wsi_disp<wbr>lay.c b/src/amd/vulkan/radv_wsi_disp<wbr>lay.c<br>
new file mode 100644<br>
index 00000000000..b0a4db0344b<br>
--- /dev/null<br>
+++ b/src/amd/vulkan/radv_wsi_disp<wbr>lay.c<br>
@@ -0,0 +1,143 @@<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 <stdbool.h><br>
+#include <string.h><br>
+#include <unistd.h><br>
+#include <fcntl.h><br>
+#include "radv_private.h"<br>
+#include "radv_cs.h"<br>
+#include "util/disk_cache.h"<br>
+#include "util/strtod.h"<br>
+#include "vk_util.h"<br>
+#include <xf86drm.h><br>
+#include <xf86drmMode.h><br>
+#include <amdgpu.h><br>
+#include <amdgpu_drm.h><br>
+#include "winsys/amdgpu/radv_amdgpu_win<wbr>sys_public.h"<br>
+#include "ac_llvm_util.h"<br>
+#include "vk_format.h"<br>
+#include "sid.h"<br>
+#include "util/debug.h"<br>
+#include "wsi_common_display.h"<br>
+<br>
+#define MM_PER_PIXEL (1.0/96.0 * 25.4)<br>
+<br>
+VkResult<br>
+radv_GetPhysicalDeviceDisplay<wbr>PropertiesKHR(<wbr>VkPhysicalDevice physical_device,<br>
+ uint32_t *property_count,<br>
+ VkDisplayPropertiesKHR *properties)<br>
+{<br>
+ RADV_FROM_HANDLE(radv_physica<wbr>l_device, pdevice, physical_device);<br>
+<br>
+ return wsi_display_get_physical_devic<wbr>e_display_properties(physical_<wbr>device,<br>
+ &pdevice->wsi_device,<br>
+ property_count,<br>
+ properties);<br>
+}<br>
+<br>
+VkResult<br>
+radv_GetPhysicalDeviceDisplay<wbr>PlanePropertiesKHR(<wbr>VkPhysicalDevice physical_device,<br>
+ uint32_t *property_count,<br>
+ VkDisplayPlanePropertiesKHR *properties)<br>
+{<br>
+ RADV_FROM_HANDLE(radv_physica<wbr>l_device, pdevice, physical_device);<br>
+<br>
+ return wsi_display_get_physical_devic<wbr>e_display_plane_properties(<wbr>physical_device,<br>
+ &pdevice->wsi_device,<br>
+ property_count,<br>
+ properties);<br>
+}<br>
+<br>
+VkResult<br>
+radv_GetDisplayPlaneSupported<wbr>DisplaysKHR(VkPhysicalDevice physical_device,<br>
+ uint32_t plane_index,<br>
+ uint32_t *display_count,<br>
+ VkDisplayKHR *displays)<br>
+{<br>
+ RADV_FROM_HANDLE(radv_physica<wbr>l_device, pdevice, physical_device);<br>
+<br>
+ return wsi_display_get_display_plane_<wbr>supported_displays(physical_de<wbr>vice,<br>
+ &pdevice->wsi_device,<br>
+ plane_index,<br>
+ display_count,<br>
+ displays);<br>
+}<br>
+<br>
+<br>
+VkResult<br>
+radv_GetDisplayModeProperties<wbr>KHR(VkPhysicalDevice physical_device,<br>
+ VkDisplayKHR display,<br>
+ uint32_t *property_count,<br>
+ VkDisplayModePropertiesKHR *properties)<br>
+{<br>
+ RADV_FROM_HANDLE(radv_physica<wbr>l_device, pdevice, physical_device);<br>
+<br>
+ return wsi_display_get_display_mode_p<wbr>roperties(physical_device,<br>
+ &pdevice->wsi_device,<br>
+ display,<br>
+ property_count,<br>
+ properties);<br>
+}<br>
+<br>
+VkResult<br>
+radv_CreateDisplayModeKHR(VkP<wbr>hysicalDevice physical_device,<br>
+ VkDisplayKHR display,<br>
+ const VkDisplayModeCreateInfoKHR *create_info,<br>
+ const VkAllocationCallbacks *allocator,<br>
+ VkDisplayModeKHR *mode)<br>
+{<br>
+ return VK_ERROR_INITIALIZATION_FAILED<wbr>;<br>
+}<br>
+<br>
+<br>
+VkResult<br>
+radv_GetDisplayPlaneCapabilit<wbr>iesKHR(VkPhysicalDevice physical_device,<br>
+ VkDisplayModeKHR mode_khr,<br>
+ uint32_t plane_index,<br>
+ VkDisplayPlaneCapabilitiesKHR *capabilities)<br>
+{<br>
+ RADV_FROM_HANDLE(radv_physica<wbr>l_device, pdevice, physical_device);<br>
+<br>
+ return wsi_get_display_plane_capabili<wbr>ties(physical_device,<br>
+ &pdevice->wsi_device,<br>
+ mode_khr,<br>
+ plane_index,<br>
+ capabilities);<br>
+}<br>
+<br>
+VkResult<br>
+radv_CreateDisplayPlaneSurfac<wbr>eKHR(VkInstance _instance,<br>
+ const VkDisplaySurfaceCreateInfoKHR *create_info,<br>
+ const VkAllocationCallbacks *allocator,<br>
+ VkSurfaceKHR *surface)<br>
+{<br>
+ RADV_FROM_HANDLE(radv_instanc<wbr>e, 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(_in<wbr>stance, alloc, create_info, surface);<br>
+}<br>
diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources<br>
index 9595bf42582..6c142729d94 100644<br>
--- a/src/intel/Makefile.sources<br>
+++ b/src/intel/Makefile.sources<br>
@@ -240,6 +240,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 23fa877e77d..7c428a799d7 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>
@@ -187,6 +187,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_SO<wbr>URCES = $(VULKAN_SOURCES)<br>
vulkan_libvulkan_common_la_CF<wbr>LAGS = $(VULKAN_CFLAGS)<br>
diff --git a/src/intel/vulkan/anv_device.<wbr>c b/src/intel/vulkan/anv_device.<wbr>c<br>
index 86c1bdc1d51..9614907fda3 100644<br>
--- a/src/intel/vulkan/anv_device.<wbr>c<br>
+++ b/src/intel/vulkan/anv_device.<wbr>c<br>
@@ -277,14 +277,25 @@ anv_physical_device_init_uuids<wbr>(struct anv_physical_device *device)<br>
static VkResult<br>
anv_physical_device_init(stru<wbr>ct anv_physical_device *device,<br>
struct anv_instance *instance,<br>
- const char *path)<br>
+ const char *primary_path,<br>
+ const char *render_path)<br>
{<br>
VkResult result;<br>
- int fd;<br>
+ int fd = -1;<br>
+ const char *path;<br>
<br>
brw_process_intel_debug_variab<wbr>le();<br>
<br>
- fd = open(path, O_RDWR | O_CLOEXEC);<br>
+ if (instance->enabled_extensions.<wbr>KHR_display) {<br>
+ path = primary_path;<br>
+ fd = open(path, O_RDWR | O_CLOEXEC);<br>
+ }<br>
+<br>
+ if (fd < 0) {<br>
+ path = render_path;<br>
+ fd = open(path, O_RDWR | O_CLOEXEC);<br>
+ }<br></blockquote><div><br></div><div>It seems a little odd to me to default to opening the master node and then fall back to the render node if it doesn't work. I suppose that's probably ok so long as we ensure that vkGetPhysicalDeviceDisplayProp<wbr>ertiesKHR returns no displays if we're on the render node.<br><br></div><div>We could always go back to the DRM fd extension idea but I'm not coming up with something nice and clean in the 60 seconds I've thought about it.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
if (fd < 0)<br>
return vk_error(VK_ERROR_INCOMPATIBLE<wbr>_DRIVER);<br>
<br>
@@ -652,6 +663,7 @@ anv_enumerate_devices(struct anv_instance *instance)<br>
<br>
result = anv_physical_device_init(&inst<wbr>ance->physicalDevice,<br>
instance,<br>
+ devices[i]->nodes[DRM_NODE_PRI<wbr>MARY],<br>
devices[i]->nodes[DRM_NODE_RE<wbr>NDER]);<br>
if (result != VK_ERROR_INCOMPATIBLE_DRIVER)<br>
break;<br>
diff --git a/src/intel/vulkan/anv_extensi<wbr>ons.py b/src/intel/vulkan/anv_extensi<wbr>ons.py<br>
index 581921e62a1..978a219e2b2 100644<br>
--- a/src/intel/vulkan/anv_extensi<wbr>ons.py<br>
+++ b/src/intel/vulkan/anv_extensi<wbr>ons.py<br>
@@ -83,6 +83,7 @@ EXTENSIONS = [<br>
Extension('VK_KHR_wayland_sur<wbr>face', 6, 'VK_USE_PLATFORM_WAYLAND_KHR')<wbr>,<br>
Extension('VK_KHR_xcb_<wbr>surface', 6, 'VK_USE_PLATFORM_XCB_KHR'),<br>
Extension('VK_KHR_xlib_surfac<wbr>e', 6, 'VK_USE_PLATFORM_XLIB_KHR'),<br>
+ Extension('VK_KHR_display', 1, 'VK_USE_PLATFORM_DISPLAY_KHR')<wbr>,<br>
Extension('VK_KHX_multiview',<wbr> 1, True),<br>
Extension('VK_EXT_debug_repor<wbr>t', 8, True),<br>
Extension('VK_EXT_external_me<wbr>mory_dma_buf', 1, True),<br>
diff --git a/src/intel/vulkan/anv_extensi<wbr>ons_gen.py b/src/intel/vulkan/anv_extensi<wbr>ons_gen.py<br>
index 33827ecd015..84d07f9767a 100644<br>
--- a/src/intel/vulkan/anv_extensi<wbr>ons_gen.py<br>
+++ b/src/intel/vulkan/anv_extensi<wbr>ons_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}_KH<wbr>R<br>
# undef VK_USE_PLATFORM_${platform}_KH<wbr>R<br>
# define VK_USE_PLATFORM_${platform}_KH<wbr>R 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>
const VkExtensionProperties anv_instance_extensions[ANV_IN<wbr>STANCE_EXTENSION_COUNT] = {<br>
%for ext in instance_extensions:<br>
diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c<br>
index 6082c3dd093..f86d83589ea 100644<br>
--- a/src/intel/vulkan/anv_wsi.c<br>
+++ b/src/intel/vulkan/anv_wsi.c<br>
@@ -39,7 +39,8 @@ anv_init_wsi(struct anv_physical_device *physical_device)<br>
return wsi_device_init(&physical_devi<wbr>ce->wsi_device,<br>
anv_physical_device_to_<wbr>handle(physical_device),<br>
anv_wsi_proc_addr,<br>
- &physical_device->instance->al<wbr>loc);<br>
+ &physical_device->instance->al<wbr>loc,<br>
+ physical_device->local_fd);<br>
}<br>
<br>
void<br>
diff --git a/src/intel/vulkan/anv_wsi_dis<wbr>play.c b/src/intel/vulkan/anv_wsi_dis<wbr>play.c<br>
new file mode 100644<br>
index 00000000000..9b00d7f02e4<br>
--- /dev/null<br>
+++ b/src/intel/vulkan/anv_wsi_dis<wbr>play.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>
+<br>
+VkResult<br>
+anv_GetPhysicalDeviceDisplayP<wbr>ropertiesKHR(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_devic<wbr>e_display_properties(physical_<wbr>device,<br>
+ &pdevice->wsi_device,<br>
+ property_count,<br>
+ properties);<br>
+}<br>
+<br>
+VkResult<br>
+anv_GetPhysicalDeviceDisplayP<wbr>lanePropertiesKHR(<wbr>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_devic<wbr>e_display_plane_properties(<wbr>physical_device,<br>
+ &pdevice->wsi_device,<br>
+ property_count,<br>
+ properties);<br>
+}<br>
+<br>
+VkResult<br>
+anv_GetDisplayPlaneSupportedD<wbr>isplaysKHR(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_de<wbr>vice,<br>
+ &pdevice->wsi_device,<br>
+ plane_index,<br>
+ display_count,<br>
+ displays);<br>
+}<br>
+<br>
+<br>
+VkResult<br>
+anv_GetDisplayModePropertiesK<wbr>HR(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_p<wbr>roperties(physical_device,<br>
+ &pdevice->wsi_device,<br>
+ display,<br>
+ property_count,<br>
+ properties);<br>
+}<br>
+<br>
+VkResult<br>
+anv_CreateDisplayModeKHR(VkPh<wbr>ysicalDevice physical_device,<br>
+ VkDisplayKHR display,<br>
+ const VkDisplayModeCreateInfoKHR *create_info,<br>
+ const VkAllocationCallbacks *allocator,<br>
+ VkDisplayModeKHR *mode)<br>
+{<br>
+ return VK_ERROR_INITIALIZATION_FAILED<wbr>;<br>
+}<br>
+<br>
+<br>
+VkResult<br>
+anv_GetDisplayPlaneCapabiliti<wbr>esKHR(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_capabili<wbr>ties(physical_device,<br>
+ &pdevice->wsi_device,<br>
+ mode_khr,<br>
+ plane_index,<br>
+ capabilities);<br>
+}<br>
+<br>
+VkResult<br>
+anv_CreateDisplayPlaneSurface<wbr>KHR(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(_in<wbr>stance, alloc, create_info, surface);<br>
+}<br>
diff --git a/src/intel/vulkan/meson.build b/src/intel/vulkan/meson.build<br>
index 69ec26e19b6..2e2ab8f7ecd 100644<br>
--- a/src/intel/vulkan/meson.build<br>
+++ b/src/intel/vulkan/meson.build<br>
@@ -171,6 +171,13 @@ if with_platform_wayland<br>
libanv_files += files('anv_wsi_wayland.c')<br>
endif<br>
<br>
+if with_platform_display<br>
+ anv_flags += [<br>
+ '-DVK_USE_PLATFORM_DISPLAY_KHR<wbr>',<br>
+ ]<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>
diff --git a/src/vulkan/Makefile.am b/src/vulkan/Makefile.am<br>
index 037436c1cd7..c33ac5758f7 100644<br>
--- a/src/vulkan/Makefile.am<br>
+++ b/src/vulkan/Makefile.am<br>
@@ -57,6 +57,13 @@ AM_CPPFLAGS += \<br>
VULKAN_WSI_SOURCES += $(VULKAN_WSI_X11_FILES)<br>
endif<br>
<br>
+if HAVE_PLATFORM_DISPLAY<br>
+AM_CPPFLAGS += \<br>
+ -DVK_USE_PLATFORM_DISPLAY_KHR<br>
+<br>
+VULKAN_WSI_SOURCES += $(VULKAN_WSI_DISPLAY_FILES)<br>
+endif<br>
+<br>
BUILT_SOURCES += $(VULKAN_WSI_WAYLAND_GENERATED<wbr>_FILES)<br>
CLEANFILES = $(BUILT_SOURCES)<br>
<br>
diff --git a/src/vulkan/Makefile.sources b/src/vulkan/Makefile.sources<br>
index a0a24ce7de8..3642c7662c4 100644<br>
--- a/src/vulkan/Makefile.sources<br>
+++ b/src/vulkan/Makefile.sources<br>
@@ -17,6 +17,10 @@ VULKAN_WSI_X11_FILES := \<br>
wsi/wsi_common_x11.c \<br>
wsi/wsi_common_x11.h<br>
<br>
+VULKAN_WSI_DISPLAY_FILES := \<br>
+ wsi/wsi_common_display.c \<br>
+ wsi/wsi_common_display.h<br>
+<br>
VULKAN_UTIL_FILES := \<br>
util/vk_alloc.h \<br>
util/vk_debug_report.c \<br>
diff --git a/src/vulkan/wsi/meson.build b/src/vulkan/wsi/meson.build<br>
index bd0fd3cc53e..743631a6113 100644<br>
--- a/src/vulkan/wsi/meson.build<br>
+++ b/src/vulkan/wsi/meson.build<br>
@@ -57,6 +57,16 @@ if with_platform_wayland<br>
]<br>
endif<br>
<br>
+if with_platform_display<br>
+ vulkan_wsi_args += [<br>
+ '-DVK_USE_PLATFORM_DISPLAY_KHR<wbr>',<br>
+ ]<br>
+ files_vulkan_wsi += files(<br>
+ 'wsi_common_display.c',<br>
+ 'wsi_common_display.h',<br>
+ )<br>
+endif<br>
+<br>
libvulkan_wsi = static_library(<br>
'vulkan_wsi',<br>
files_vulkan_wsi,<br>
diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c<br>
index 90ed07b7857..c0a285e5814 100644<br>
--- a/src/vulkan/wsi/wsi_common.c<br>
+++ b/src/vulkan/wsi/wsi_common.c<br>
@@ -29,7 +29,8 @@ VkResult<br>
wsi_device_init(struct wsi_device *wsi,<br>
VkPhysicalDevice pdevice,<br>
WSI_FN_GetPhysicalDeviceProcA<wbr>ddr proc_addr,<br>
- const VkAllocationCallbacks *alloc)<br>
+ const VkAllocationCallbacks *alloc,<br>
+ int device_fd)<br>
{<br>
VkResult result;<br>
<br>
@@ -89,6 +90,19 @@ wsi_device_init(struct wsi_device *wsi,<br>
}<br>
#endif<br>
<br>
+#ifdef VK_USE_PLATFORM_DISPLAY_KHR<br>
+ result = wsi_display_init_wsi(wsi, alloc, pdevice, device_fd);<br>
+ if (result != VK_SUCCESS) {<br>
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR<br>
+ wsi_wl_finish_wsi(wsi, alloc);<br>
+#endif<br>
+#ifdef VK_USE_PLATFORM_XCB_KHR<br>
+ wsi_x11_finish_wsi(wsi, alloc);<br>
+#endif<br>
+ return result;<br>
+ }<br>
+#endif<br></blockquote><div><br></div><div>Not your problem but we really need a better clean-up path....<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
return VK_SUCCESS;<br>
}<br>
<br>
@@ -96,6 +110,9 @@ void<br>
wsi_device_finish(struct wsi_device *wsi,<br>
const VkAllocationCallbacks *alloc)<br>
{<br>
+#ifdef VK_USE_PLATFORM_DISPLAY_KHR<br>
+ wsi_display_finish_wsi(wsi, alloc);<br>
+#endif<br>
#ifdef VK_USE_PLATFORM_WAYLAND_KHR<br>
wsi_wl_finish_wsi(wsi, alloc);<br>
#endif<br>
diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h<br>
index 3e0d3be1c24..1cb6aaebca0 100644<br>
--- a/src/vulkan/wsi/wsi_common.h<br>
+++ b/src/vulkan/wsi/wsi_common.h<br>
@@ -50,7 +50,7 @@ struct wsi_memory_allocate_info {<br>
<br>
struct wsi_interface;<br>
<br>
-#define VK_ICD_WSI_PLATFORM_MAX 5<br>
+#define VK_ICD_WSI_PLATFORM_MAX 6<br>
<br>
struct wsi_device {<br>
VkPhysicalDeviceMemoryProperti<wbr>es memory_props;<br>
@@ -93,7 +93,8 @@ VkResult<br>
wsi_device_init(struct wsi_device *wsi,<br>
VkPhysicalDevice pdevice,<br>
WSI_FN_GetPhysicalDeviceProcA<wbr>ddr proc_addr,<br>
- const VkAllocationCallbacks *alloc);<br>
+ const VkAllocationCallbacks *alloc,<br>
+ int device_fd);<br>
<br>
void<br>
wsi_device_finish(struct wsi_device *wsi,<br>
diff --git a/src/vulkan/wsi/wsi_common_di<wbr>splay.c b/src/vulkan/wsi/wsi_common_di<wbr>splay.c<br>
new file mode 100644<br>
index 00000000000..2732b1dd721<br>
--- /dev/null<br>
+++ b/src/vulkan/wsi/wsi_common_di<wbr>splay.c<br>
@@ -0,0 +1,1368 @@<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 "util/macros.h"<br>
+#include <stdlib.h><br>
+#include <stdio.h><br>
+#include <unistd.h><br>
+#include <errno.h><br>
+#include <string.h><br>
+#include <fcntl.h><br>
+#include <poll.h><br>
+#include <stdbool.h><br>
+#include <math.h><br>
+#include <xf86drm.h><br>
+#include <xf86drmMode.h><br>
+#include "util/hash_table.h"<br>
+#include "util/list.h"<br>
+<br>
+#include "vk_util.h"<br>
+#include "wsi_common_private.h"<br>
+#include "wsi_common_display.h"<br>
+#include "wsi_common_queue.h"<br>
+<br>
+#if 0<br>
+#define wsi_display_debug(...) fprintf(stderr, __VA_ARGS__)<br>
+#define wsi_display_debug_code(...) __VA_ARGS__<br>
+#else<br>
+#define wsi_display_debug(...)<br>
+#define wsi_display_debug_code(...)<br>
+#endif<br>
+<br>
+/* These have lifetime equal to the instance, so they effectively<br>
+ * never go away. This means we must keep track of them separately<br>
+ * from all other resources.<br>
+ */<br>
+typedef struct wsi_display_mode {<br>
+ struct list_head list;<br>
+ struct wsi_display_connector *connector;<br>
+ bool valid; /* was found in most recent poll */<br>
+ bool preferred;<br>
+ uint32_t clock; /* in kHz */<br>
+ uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;<br>
+ uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;<br>
+ uint32_t flags;<br></blockquote><div><br></div><div>Would it make anything easier if we just storred the DRM struct here? "No" is a perfectly valid answer.<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+} wsi_display_mode;<br>
+<br>
+typedef struct wsi_display_connector {<br>
+ struct list_head list;<br>
+ struct wsi_display *wsi;<br>
+ uint32_t id;<br>
+ uint32_t crtc_id;<br>
+ char *name;<br>
+ bool connected;<br>
+ bool active;<br>
+ wsi_display_mode *current_mode;<br>
+ drmModeModeInfo current_drm_mode;<br>
+} wsi_display_connector;<br>
+<br>
+struct wsi_display {<br>
+ struct wsi_interface base;<br>
+<br>
+ const VkAllocationCallbacks *alloc;<br>
+ VkPhysicalDevice physical_device;<br>
+<br>
+ int master_fd;<br>
+ int render_fd;<br>
+<br>
+ pthread_mutex_t wait_mutex;<br>
+ pthread_cond_t wait_cond;<br>
+ pthread_t wait_thread;<br>
+<br>
+ struct list_head connectors;<br>
+<br>
+ struct list_head display_modes;<br>
+};<br>
+<br>
+enum wsi_image_state {<br>
+ wsi_image_idle,<br>
+ wsi_image_drawing,<br>
+ wsi_image_queued,<br>
+ wsi_image_flipping,<br>
+ wsi_image_displaying<br>
+};<br>
+<br>
+struct wsi_display_image {<br>
+ struct wsi_image base;<br>
+ struct wsi_display_swapchain *chain;<br>
+ enum wsi_image_state state;<br>
+ uint32_t fb_id;<br>
+ uint64_t flip_sequence;<br>
+};<br>
+<br>
+struct wsi_display_swapchain {<br>
+ struct wsi_swapchain base;<br>
+ struct wsi_display *wsi;<br>
+ VkIcdSurfaceDisplay *surface;<br>
+ uint64_t flip_sequence;<br>
+ struct wsi_display_image images[0];<br>
+};<br>
+<br>
+ICD_DEFINE_NONDISP_HANDLE_CAS<wbr>TS(wsi_display_mode, VkDisplayModeKHR)<br>
+ICD_DEFINE_NONDISP_HANDLE_CAS<wbr>TS(wsi_display_connector, VkDisplayKHR)<br>
+<br>
+static bool<br>
+wsi_display_mode_matches_drm(<wbr>wsi_display_mode *wsi,<br>
+ drmModeModeInfoPtr drm)<br>
+{<br>
+ return wsi->clock == drm->clock &&<br>
+ wsi->hdisplay == drm->hdisplay &&<br>
+ wsi->hsync_start == drm->hsync_start &&<br>
+ wsi->hsync_end == drm->hsync_end &&<br>
+ wsi->htotal == drm->htotal &&<br>
+ wsi->hskew == drm->hskew &&<br>
+ wsi->vdisplay == drm->vdisplay &&<br>
+ wsi->vsync_start == drm->vsync_start &&<br>
+ wsi->vsync_end == drm->vsync_end &&<br>
+ wsi->vtotal == drm->vtotal &&<br>
+ wsi->vscan == drm->vscan &&<br>
+ wsi->flags == drm->flags;<br>
+}<br>
+<br>
+static double<br>
+wsi_display_mode_refresh(stru<wbr>ct wsi_display_mode *wsi)<br>
+{<br>
+ return (double) wsi->clock * 1000.0 / ((double) wsi->htotal * (double) wsi->vtotal * (double) (wsi->vscan + 1));<br>
+}<br>
+<br>
+static uint64_t wsi_get_current_monotonic(void<wbr>)<br>
+{<br>
+ struct timespec tv;<br>
+<br>
+ clock_gettime(CLOCK_<wbr>MONOTONIC, &tv);<br>
+ return tv.tv_nsec + tv.tv_sec*1000000000ull;<br>
+}<br></blockquote><div><br></div><div>This should probably gone in a helper one day. Meh.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+static struct wsi_display_mode *<br>
+wsi_display_find_drm_mode(str<wbr>uct wsi_device *wsi_device,<br>
+ struct wsi_display_connector *connector,<br>
+ drmModeModeInfoPtr mode)<br>
+{<br>
+ struct wsi_display *wsi = (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLA<wbr>TFORM_DISPLAY];<br>
+ struct wsi_display_mode *display_mode;<br>
+<br>
+ LIST_FOR_EACH_ENTRY(display_m<wbr>ode, &wsi->display_modes, list) {<br>
+ if (display_mode->connector == connector &&<br>
+ wsi_display_mode_matches_drm(d<wbr>isplay_mode, mode))<br></blockquote><div><br></div><div>Any particular reason why the list of modes is global and not in the connector? It seems like it would be a tiny bit more efficient and convenient to put the list in the connector.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ return display_mode;<br>
+ }<br>
+ return NULL;<br>
+}<br>
+<br>
+static void<br>
+wsi_display_invalidate_connec<wbr>tor_modes(struct wsi_device *wsi_device,<br>
+ struct wsi_display_connector *connector)<br>
+{<br>
+ struct wsi_display *wsi = (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLA<wbr>TFORM_DISPLAY];<br>
+ struct wsi_display_mode *display_mode;<br>
+<br>
+ LIST_FOR_EACH_ENTRY(display_m<wbr>ode, &wsi->display_modes, list)<br>
+ if (display_mode->connector == connector)<br>
+ display_mode->valid = false;<br></blockquote><div><br></div><div>Please use braces for loops containing more than one line.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+}<br>
+<br>
+static VkResult<br>
+wsi_display_register_drm_mode<wbr>(struct wsi_device *wsi_device,<br>
+ struct wsi_display_connector *connector,<br>
+ drmModeModeInfoPtr drm_mode)<br>
+{<br>
+ struct wsi_display *wsi = (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLA<wbr>TFORM_DISPLAY];<br>
+ struct wsi_display_mode *display_mode;<br>
+<br>
+ display_mode = wsi_display_find_drm_mode(wsi_<wbr>device, connector, drm_mode);<br>
+<br>
+ if (display_mode) {<br>
+ display_mode->valid = true;<br>
+ return VK_SUCCESS;<br>
+ }<br>
+<br>
+ display_mode = vk_alloc(wsi->alloc, sizeof (struct wsi_display_mode), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJ<wbr>ECT);<br></blockquote><div><br></div>Since we're allocating these in a physical device query, we need to use the INSTANCE scope. the OBJECT scope is intended for vkCreate functions to allocated data that will live no longer than the associated vkDestroy function.<br><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ if (!display_mode)<br>
+ return VK_ERROR_OUT_OF_HOST_MEMORY;<br>
+<br>
+ display_mode->connector = connector;<br>
+ display_mode->valid = true;<br>
+ display_mode->preferred = (drm_mode->type & DRM_MODE_TYPE_PREFERRED) != 0;<br>
+ display_mode->clock = drm_mode->clock; /* kHz */<br>
+ display_mode->hdisplay = drm_mode->hdisplay;<br>
+ display_mode->hsync_start = drm_mode->hsync_start;<br>
+ display_mode->hsync_end = drm_mode->hsync_end;<br>
+ display_mode->htotal = drm_mode->htotal;<br>
+ display_mode->hskew = drm_mode->hskew;<br>
+ display_mode->vdisplay = drm_mode->vdisplay;<br>
+ display_mode->vsync_start = drm_mode->vsync_start;<br>
+ display_mode->vsync_end = drm_mode->vsync_end;<br>
+ display_mode->vtotal = drm_mode->vtotal;<br>
+ display_mode->vscan = drm_mode->vscan;<br>
+ display_mode->flags = drm_mode->flags;<br>
+<br>
+ LIST_ADDTAIL(&display_mode->l<wbr>ist, &wsi->display_modes);<br>
+ return VK_SUCCESS;<br>
+}<br>
+<br>
+/*<br>
+ * Update our information about a specific connector<br>
+ */<br>
+<br>
+static struct wsi_display_connector *<br>
+wsi_display_find_connector(st<wbr>ruct wsi_device *wsi_device,<br>
+ uint32_t connector_id)<br>
+{<br>
+ struct wsi_display *wsi = (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLA<wbr>TFORM_DISPLAY];<br>
+ struct wsi_display_connector *connector;<br>
+<br>
+ connector = NULL;<br>
+ LIST_FOR_EACH_ENTRY(<wbr>connector, &wsi->connectors, list) {<br>
+ if (connector->id == connector_id)<br>
+ return connector;<br>
+ }<br>
+<br>
+ return NULL;<br>
+}<br>
+<br>
+static struct wsi_display_connector *<br>
+wsi_display_alloc_connector(s<wbr>truct wsi_display *wsi,<br>
+ uint32_t connector_id)<br>
+{<br>
+ struct wsi_display_connector *connector;<br>
+<br>
+ connector = vk_alloc(wsi->alloc, sizeof (struct wsi_display_connector), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJ<wbr>ECT);<br></blockquote><div><br></div><div>VK_SYSTEM_ALLOCATION_SCOPE_<wbr>INSTANCE<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ memset(connector, '\0', sizeof (*connector));<br></blockquote><div><br></div><div>Just use vk_zalloc().<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ connector->id = connector_id;<br>
+ connector->wsi = wsi;<br>
+ connector->active = false;<br>
+ /* XXX use EDID name */<br>
+ connector->name = "monitor";<br>
+ return connector;<br>
+}<br>
+<br>
+static struct wsi_display_connector *<br>
+wsi_display_get_connector(str<wbr>uct wsi_device *wsi_device,<br>
+ uint32_t connector_id)<br>
+{<br>
+ struct wsi_display *wsi = (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLA<wbr>TFORM_DISPLAY];<br>
+ struct wsi_display_connector *connector;<br>
+ drmModeConnectorPtr drm_connector;<br>
+ VkResult result;<br>
+ int m;<br>
+<br>
+ if (wsi->master_fd < 0)<br>
+ return NULL;<br>
+<br>
+ drm_connector = drmModeGetConnector(wsi->maste<wbr>r_fd, connector_id);<br>
+ if (!drm_connector)<br>
+ return NULL;<br>
+<br>
+ connector = wsi_display_find_connector(wsi<wbr>_device, connector_id);<br>
+<br>
+ if (!connector) {<br>
+ connector = wsi_display_alloc_connector(ws<wbr>i, connector_id);<br>
+ if (!connector) {<br>
+ drmModeFreeConnector(drm_conn<wbr>ector);<br>
+ return NULL;<br>
+ }<br>
+ LIST_ADDTAIL(&connector->list, &wsi->connectors);<br>
+ }<br>
+<br>
+ connector->connected = drm_connector->connection != DRM_MODE_DISCONNECTED;<br>
+<br>
+ /* Mark all connector modes as invalid */<br>
+ wsi_display_invalidate_connec<wbr>tor_modes(wsi_device, connector);<br>
+<br>
+ /*<br>
+ * List current modes, adding new ones and marking existing ones as<br>
+ * valid<br>
+ */<br>
+ for (m = 0; m < drm_connector->count_modes; m++) {<br>
+ result = wsi_display_register_drm_mode(<wbr>wsi_device,<br>
+ connector,<br>
+ &drm_connector->modes[m]);<br>
+ if (result != VK_SUCCESS) {<br>
+ drmModeFreeConnector(drm_conn<wbr>ector);<br>
+ return NULL;<br>
+ }<br>
+ }<br>
+<br>
+ drmModeFreeConnector(drm_conn<wbr>ector);<br>
+<br>
+ return connector;<br>
+}<br>
+<br>
+#define MM_PER_PIXEL (1.0/96.0 * 25.4)<br></blockquote><div><br></div><div>Hooray for obviously false fixed constants!<br><br></div><div>I know the answer to this will be "EDIDs lie, never trust them!" but can we get the real value somehow? As someone who has a 13" laptop with a 3200x1800 display, I know that number isn't always right. :-)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+static void<br>
+wsi_display_fill_in_display_p<wbr>roperties(struct wsi_device *wsi_device,<br>
+ struct wsi_display_connector *connector,<br>
+ VkDisplayPropertiesKHR *properties)<br>
+{<br>
+ struct wsi_display *wsi = (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLA<wbr>TFORM_DISPLAY];<br>
+ struct wsi_display_mode *display_mode, *preferred_mode = NULL;;<br></blockquote><div><br></div><div>double-;;<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ properties->display = wsi_display_connector_to_handl<wbr>e(connector);<br>
+ properties->displayName = connector->name;<br>
+<br>
+ /* Find the preferred mode and assume that's the physical resolution */<br>
+<br>
+ LIST_FOR_EACH_ENTRY(display_m<wbr>ode, &wsi->display_modes, list) {<br>
+ if (display_mode->valid && display_mode->connector == connector && display_mode->preferred) {<br>
+ preferred_mode = display_mode;<br>
+ break;<br>
+ }<br>
+ }<br>
+<br>
+ if (preferred_mode) {<br>
+ properties->physicalResolution<wbr>.width = preferred_mode->hdisplay;<br>
+ properties->physicalResolution<wbr>.height = preferred_mode->vdisplay;<br>
+ } else {<br>
+ properties->physicalResolution<wbr>.width = 1024;<br>
+ properties->physicalResolution<wbr>.height = 768;<br></blockquote><br></div><div class="gmail_quote">From the Vulkan spec:<br><br> Note:<br> For devices which have no natural value to return here, implementations
<strong class="gmail-purple">should</strong> return the maximum resolution supported.<br><br></div><div class="gmail_quote">We should walk the list and pick the biggest one.<br></div><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ }<br>
+<br>
+ /* Make up physical size based on 96dpi */<br>
+ properties->physicalDimension<wbr>s.width = floor(properties->physicalReso<wbr>lution.width * MM_PER_PIXEL + 0.5);<br>
+ properties->physicalDimension<wbr>s.height = floor(properties->physicalReso<wbr>lution.height * MM_PER_PIXEL + 0.5);<br></blockquote><div><br></div><div>See question about MM_PER_PIXEL above<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ properties->supportedTransfor<wbr>ms = VK_SURFACE_TRANSFORM_IDENTITY_<wbr>BIT_KHR;<br></blockquote><div><br></div><div>I know i915 can do better at least in some cases. Is there a practical way to expose this? If not, I'm fine with just exposing IDENTITY.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ properties->persistentContent = 0;<br>
+}<br>
+<br>
+/*<br>
+ * Implement vkGetPhysicalDeviceDisplayProp<wbr>ertiesKHR (VK_KHR_display)<br>
+ */<br>
+VkResult<br>
+wsi_display_get_physical_devi<wbr>ce_display_properties(VkPhysic<wbr>alDevice physical_device,<br>
+ struct wsi_device *wsi_device,<br>
+ uint32_t *property_count,<br>
+ VkDisplayPropertiesKHR *properties)<br>
+{<br>
+ struct wsi_display *wsi = (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLA<wbr>TFORM_DISPLAY];<br>
+ struct wsi_display_connector *connector;<br>
+ int c;<br>
+ uint32_t connected;<br>
+ uint32_t property_count_requested = *property_count;<br>
+ drmModeResPtr mode_res;<br>
+<br>
+ if (wsi->master_fd < 0)<br>
+ return VK_ERROR_INITIALIZATION_FAILED<wbr>;<br>
+<br>
+ mode_res = drmModeGetResources(wsi->maste<wbr>r_fd);<br>
+<br>
+ if (!mode_res)<br>
+ return VK_ERROR_INITIALIZATION_FAILED<wbr>;<br></blockquote><div><br></div><div>This error is not allowed for this function. We should just write 0 to property_count and return VK_SUCCESS. Maybe add some asserts for debug builds if you really think this shouldn't ever happen.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ connected = 0;<br>
+<br>
+ /* Get current information */<br>
+ for (c = 0; c < mode_res->count_connectors; c++) {<br>
+ connector = wsi_display_get_connector(wsi_<wbr>device, mode_res->connectors[c]);<br>
+<br>
+ if (!connector) {<br>
+ drmModeFreeResources(mode_<wbr>res);<br>
+ return VK_ERROR_OUT_OF_HOST_MEMORY;<br>
+ }<br>
+<br>
+ if (connector->connected)<br>
+ connected++;<br>
+ }<br>
+<br>
+ /* Fill in property information if requested */<br>
+ if (properties != NULL) {<br>
+ connected = 0;<br>
+<br>
+ for (c = 0; c < mode_res->count_connectors; c++) {<br>
+ connector = wsi_display_find_connector(wsi<wbr>_device, mode_res->connectors[c]);<br>
+<br>
+ if (connector && connector->connected) {<br>
+ if (connected < property_count_requested) {<br>
+ wsi_display_fill_in_display_p<wbr>roperties(wsi_device,<br>
+ connector,<br>
+ &properties[connected]);<br>
+ }<br>
+ connected++;<br>
+ }<br>
+ }<br>
+ }<br></blockquote><div><br></div><div>This could be made a lot easier with vk_outarray:<br><br></div><div>VK_OUTARRAY_MAKE(conn, properties, property_count);<br><br></div><div>for (int c = 0; c < mode_res->count_connectors; c++) {<br></div><div> connector = wsi_display_get_connector(wsi_device, mode_res->connectors[c]);<br> if (!connector) {<br>
drmModeFreeResources(mode_<wbr>res);<br>
return VK_ERROR_OUT_OF_HOST_MEMORY;<br>
}</div><div> if (connector->connected) {<br></div><div> vk_outarray_append(&conn, prop) {<br></div><div> wsi_display_fill_in_display_properties(wsi_device, connector, prop);<br> }<br></div><div> }<br></div><div>}<br><br></div><div>drmModeFreeResources(mode_res);<br><br></div><div>return vk_outarray_status(&conn);<br><br></div><div>It's a bit magic but a lot less typing and you don't have to think about all the details of whether or not you've gotten the return value right.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ drmModeFreeResources(mode_<wbr>res);<br>
+<br>
+ *property_count = connected;<br>
+<br>
+ if (connected > property_count_requested && properties != NULL)<br>
+ return VK_INCOMPLETE;<br>
+<br>
+ return VK_SUCCESS;<br>
+}<br>
+<br>
+/*<br>
+ * Implement vkGetPhysicalDeviceDisplayPlan<wbr>ePropertiesKHR (VK_KHR_display<br>
+ */<br>
+VkResult<br>
+wsi_display_get_physical_devi<wbr>ce_display_plane_properties(<wbr>VkPhysicalDevice physical_device,<br>
+ struct wsi_device *wsi_device,<br>
+ uint32_t *property_count,<br>
+ VkDisplayPlanePropertiesKHR *properties)<br>
+{<br>
+ struct wsi_display *wsi = (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLA<wbr>TFORM_DISPLAY];<br>
+ struct wsi_display_connector *connector;<br>
+ uint32_t property_count_requested = *property_count;<br>
+ int c;<br>
+<br>
+ if (!properties)<br>
+ property_count_requested = 0;<br>
+<br>
+ c = 0;<br>
+ LIST_FOR_EACH_ENTRY(<wbr>connector, &wsi->connectors, list) {<br>
+ if (c < property_count_requested) {<br>
+ if (connector && connector->active) {<br>
+ properties[c].currentDisplay = wsi_display_connector_to_handl<wbr>e(connector);<br>
+ properties[c].currentStackInde<wbr>x = c;<br>
+ } else {<br>
+ properties[c].currentDisplay = NULL;<br>
+ properties[c].currentStackInde<wbr>x = 0;<br></blockquote><div><br></div><div>It's not entirely clear what the stack index for a disabled plane should be. I guess 0 is as good as anything.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ }<br>
+ }<br>
+ c++;<br>
+ }<br>
+<br>
+ *property_count = c;<br>
+<br>
+ if (c > property_count_requested && properties != NULL)<br>
+ return VK_INCOMPLETE;<br></blockquote><div><br></div><div>Again, vk_outarray is your friend.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ return VK_SUCCESS;<br>
+}<br>
+<br>
+/*<br>
+ * Implement vkGetDisplayPlaneSupportedDisp<wbr>laysKHR (VK_KHR_display)<br>
+ */<br>
+<br>
+VkResult<br>
+wsi_display_get_display_plane<wbr>_supported_displays(VkPhysical<wbr>Device physical_device,<br>
+ struct wsi_device *wsi_device,<br>
+ uint32_t plane_index,<br>
+ uint32_t *display_count,<br>
+ VkDisplayKHR *displays)<br>
+{<br>
+ struct wsi_display *wsi = (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLA<wbr>TFORM_DISPLAY];<br>
+ struct wsi_display_connector *connector;<br>
+ int c;<br>
+<br>
+<br>
+ if (displays == NULL) {<br>
+ *display_count = 1;<br></blockquote><div><br></div><div>This isn't correct. The loop below could turn up no displays. Again, vk_outarray is your friend.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ return VK_SUCCESS;<br>
+ }<br>
+<br>
+ if (*display_count < 1)<br>
+ return VK_INCOMPLETE;<br>
+<br>
+ c = 0;<br>
+ LIST_FOR_EACH_ENTRY(<wbr>connector, &wsi->connectors, list) {<br>
+ if (c == plane_index) {<br>
+ *displays = wsi_display_connector_to_handl<wbr>e(connector);<br>
+ *display_count = 1;<br>
+ return VK_SUCCESS;<br>
+ }<br>
+ c++;<br>
+ }<br>
+<br>
+ *displays = 0;<br>
+ *display_count = 0;<br></blockquote><div><br></div><div>One of these is wrong. Either you have zero displays or you have one display and it's VK_NULL_HANDLE.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ return VK_SUCCESS;<br>
+}<br>
+<br>
+/*<br>
+ * Implement vkGetDisplayModePropertiesKHR (VK_KHR_display)<br>
+ */<br>
+<br>
+VkResult<br>
+wsi_display_get_display_mode_<wbr>properties(VkPhysicalDevice physical_device,<br>
+ struct wsi_device *wsi_device,<br>
+ VkDisplayKHR display,<br>
+ uint32_t *property_count,<br>
+ VkDisplayModePropertiesKHR *properties)<br>
+{<br>
+ struct wsi_display *wsi = (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLA<wbr>TFORM_DISPLAY];<br>
+ struct wsi_display_connector *connector = wsi_display_connector_from_han<wbr>dle(display);<br>
+ int i;<br>
+ struct wsi_display_mode *display_mode;<br>
+ uint32_t property_count_requested = *property_count;<br>
+<br>
+ i = 0;<br>
+<br>
+ if (properties == NULL)<br>
+ property_count_requested = 0;<br>
+<br>
+ LIST_FOR_EACH_ENTRY(display_m<wbr>ode, &wsi->display_modes, list) {<br>
+ if (display_mode->valid && display_mode->connector == connector) {<br>
+ if (i < property_count_requested) {<br>
+ properties[i].displayMode = wsi_display_mode_to_handle(dis<wbr>play_mode);<br>
+ properties[i].parameters.visib<wbr>leRegion.width = display_mode->hdisplay;<br>
+ properties[i].parameters.visib<wbr>leRegion.height = display_mode->vdisplay;<br>
+ properties[i].parameters.refre<wbr>shRate = (uint32_t) (wsi_display_mode_refresh(disp<wbr>lay_mode) * 1000 + 0.5);<br>
+ }<br>
+ i++;<br>
+ }<br>
+ }<br>
+<br>
+ *property_count = i;<br>
+<br>
+ if (i > property_count_requested && properties != NULL)<br>
+ return VK_INCOMPLETE;<br></blockquote><div><br></div><div>Yeah, I sound like a broken record now. vk_outarray. I think this one is actually correct, so you could leave it alone if you wanted.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ return VK_SUCCESS;<br>
+<br>
+}<br>
+<br>
+/*<br>
+ * Implement vkGetDisplayPlaneCapabilities<br>
+ */<br>
+VkResult<br>
+wsi_get_display_plane_capabil<wbr>ities(VkPhysicalDevice physical_device,<br>
+ struct wsi_device *wsi_device,<br>
+ VkDisplayModeKHR mode_khr,<br>
+ uint32_t plane_index,<br>
+ <wbr>VkDisplayPlaneCapabilitiesKHR *capabilities)<br>
+{<br>
+ struct wsi_display_mode *mode = wsi_display_mode_from_handle(m<wbr>ode_khr);<br>
+<br>
+ /* XXX use actual values */<br></blockquote><div><br></div><div>That would be good. I don't know enough about KMS to know where you'd get those.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ capabilities->supportedAlpha = VK_DISPLAY_PLANE_ALPHA_OPAQUE_<wbr>BIT_KHR;<br>
+ capabilities->minSrcPosition.<wbr>x = 0;<br>
+ capabilities->minSrcPosition.<wbr>y = 0;<br>
+ capabilities->maxSrcPosition.<wbr>x = 0;<br>
+ capabilities->maxSrcPosition.<wbr>y = 0;<br>
+ capabilities->minSrcExtent.wi<wbr>dth = mode->hdisplay;<br>
+ capabilities->minSrcExtent.he<wbr>ight = mode->vdisplay;<br>
+ capabilities->maxSrcExtent.wi<wbr>dth = mode->hdisplay;<br>
+ capabilities->maxSrcExtent.he<wbr>ight = mode->vdisplay;<br>
+ capabilities->minDstPosition.<wbr>x = 0;<br>
+ capabilities->minDstPosition.<wbr>y = 0;<br>
+ capabilities->maxDstPosition.<wbr>x = 0;<br>
+ capabilities->maxDstPosition.<wbr>y = 0;<br>
+ capabilities->minDstExtent.wi<wbr>dth = mode->hdisplay;<br>
+ capabilities->minDstExtent.he<wbr>ight = mode->vdisplay;<br>
+ capabilities->maxDstExtent.wi<wbr>dth = mode->hdisplay;<br>
+ capabilities->maxDstExtent.he<wbr>ight = mode->vdisplay;<br>
+ return VK_SUCCESS;<br>
+}<br>
+<br>
+VkResult<br>
+wsi_create_display_surface(Vk<wbr>Instance instance,<br>
+ const VkAllocationCallbacks *allocator,<br>
+ const VkDisplaySurfaceCreateInfoKHR *create_info,<br>
+ VkSurfaceKHR *surface_khr)<br>
+{<br>
+ VkIcdSurfaceDisplay *surface;<br>
+<br>
+ surface = vk_alloc(allocator, sizeof *surface, 8,<br>
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJ<wbr>ECT);<br>
+ if (surface == NULL)<br>
+ return VK_ERROR_OUT_OF_HOST_MEMORY;<br>
+<br>
+ surface->base.platform = VK_ICD_WSI_PLATFORM_DISPLAY;<br>
+<br>
+ surface->displayMode = create_info->displayMode;<br>
+ surface->planeIndex = create_info->planeIndex;<br>
+ surface->planeStackIndex = create_info->planeStackIndex;<br>
+ surface->transform = create_info->transform;<br>
+ surface->globalAlpha = create_info->globalAlpha;<br>
+ surface->alphaMode = create_info->alphaMode;<br>
+ surface->imageExtent = create_info->imageExtent;<br>
+<br>
+ *surface_khr = VkIcdSurfaceBase_to_handle(&su<wbr>rface->base);<br>
+ return VK_SUCCESS;<br>
+}<br>
+<br>
+<br>
+static VkResult<br>
+wsi_display_surface_get_suppo<wbr>rt(VkIcdSurfaceBase *surface,<br>
+ struct wsi_device *wsi_device,<br>
+ const VkAllocationCallbacks *allocator,<br>
+ uint32_t queueFamilyIndex,<br>
+ int local_fd,<br>
+ VkBool32* pSupported)<br>
+{<br>
+ *pSupported = VK_TRUE;<br></blockquote><div><br></div><div>As I commented above, I think we want this to be conditional on whether or not you actually got a master FD.<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ return VK_SUCCESS;<br>
+}<br>
+<br>
+static VkResult<br>
+wsi_display_surface_get_capab<wbr>ilities(VkIcdSurfaceBase *surface_base,<br>
+ VkSurfaceCapabilitiesKHR* caps)<br>
+{<br>
+ VkIcdSurfaceDisplay *surface = (VkIcdSurfaceDisplay *) surface_base;<br>
+ wsi_display_mode *mode = wsi_display_mode_from_handle(s<wbr>urface->displayMode);<br>
+<br>
+ caps->currentExtent.width = mode->hdisplay;<br>
+ caps->currentExtent.height = mode->vdisplay;<br>
+<br>
+ /* XXX Figure out extents based on driver capabilities */<br>
+ caps->maxImageExtent = caps->minImageExtent = caps->currentExtent;<br>
+<br>
+ caps->supportedCompositeAlpha = (VK_COMPOSITE_ALPHA_INHERIT_BI<wbr>T_KHR |<br>
+ VK_COMPOSITE_ALPHA_OPAQUE_BIT_<wbr>KHR);<br></blockquote><div><br></div>I don't think INHERIT is really appropreate here. I don't think it's practical to set the transparency using KMS without doing it as part of the modeset. Since it really has to be insde the WSI code, we just want OPAQUE_BIT for now.<br><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ caps->minImageCount = 2;<br>
+ caps->maxImageCount = 0;<br>
+<br>
+ caps->supportedTransforms = VK_SURFACE_TRANSFORM_IDENTITY_<wbr>BIT_KHR;<br>
+ caps->currentTransform = VK_SURFACE_TRANSFORM_IDENTITY_<wbr>BIT_KHR;<br>
+ caps->maxImageArrayLayers = 1;<br>
+ caps->supportedUsageFlags =<br>
+ VK_IMAGE_USAGE_TRANSFER_SRC_BI<wbr>T |<br>
+ VK_IMAGE_USAGE_SAMPLED_BIT |<br>
+ VK_IMAGE_USAGE_TRANSFER_DST_BI<wbr>T |<br>
+ VK_IMAGE_USAGE_COLOR_ATTACHMEN<wbr>T_BIT;<br>
+<br>
+ return VK_SUCCESS;<br>
+}<br>
+<br>
+static VkResult<br>
+wsi_display_surface_get_capab<wbr>ilities2(VkIcdSurfaceBase *icd_surface,<br>
+ const void *info_next,<br>
+ VkSurfaceCapabilities2KHR *caps)<br>
+{<br>
+ assert(caps->sType == VK_STRUCTURE_TYPE_SURFACE_CAPA<wbr>BILITIES_2_KHR);<br>
+<br>
+ return wsi_display_surface_get_capabi<wbr>lities(icd_surface, &caps->surfaceCapabilities);<br>
+}<br>
+<br>
+static const VkFormat available_surface_formats[] = {<br>
+ VK_FORMAT_B8G8R8A8_SRGB,<br>
+ VK_FORMAT_B8G8R8A8_UNORM,<br>
+}; <br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+static VkResult<br>
+wsi_display_surface_get_forma<wbr>ts(VkIcdSurfaceBase *icd_surface,<br>
+ struct wsi_device *wsi_device,<br>
+ uint32_t *surface_format_count,<br>
+ VkSurfaceFormatKHR *surface_formats)<br>
+{<br>
+ VK_OUTARRAY_MAKE(out, surface_formats, surface_format_count);<br>
+<br>
+ for (unsigned i = 0; i < ARRAY_SIZE(available_surface_f<wbr>ormats); i++) {<br>
+ vk_outarray_append(&out, f) {<br>
+ f->format = available_surface_formats[i];<br>
+ f->colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_K<wbr>HR;<br>
+ }<br>
+ }<br>
+<br>
+ return vk_outarray_status(&out);<br>
+}<br>
+<br>
+static VkResult<br>
+wsi_display_surface_get_forma<wbr>ts2(VkIcdSurfaceBase *surface,<br>
+ struct wsi_device *wsi_device,<br>
+ const void *info_next,<br>
+ uint32_t *surface_format_count,<br>
+ VkSurfaceFormat2KHR *surface_formats)<br>
+{<br>
+ VK_OUTARRAY_MAKE(out, surface_formats, surface_format_count);<br>
+<br>
+ for (unsigned i = 0; i < ARRAY_SIZE(available_surface_f<wbr>ormats); i++) {<br>
+ vk_outarray_append(&out, f) {<br>
+ assert(f->sType == VK_STRUCTURE_TYPE_SURFACE_FORM<wbr>AT_2_KHR);<br>
+ f->surfaceFormat.format = available_surface_formats[i];<br>
+ f->surfaceFormat.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_K<wbr>HR;<br>
+ }<br>
+ }<br>
+<br>
+ return vk_outarray_status(&out);<br>
+}<br></blockquote><div><br>=======================================================================<br><br></div><div>I'm done reviewing for the day. I'll try to resume tomorrow. If you'd like me to continue on the new patches, I can do that.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+static const VkPresentModeKHR available_present_modes[] = {<br>
+ VK_PRESENT_MODE_FIFO_KHR,<br>
+};<br>
+<br>
+static VkResult<br>
+wsi_display_surface_get_prese<wbr>nt_modes(VkIcdSurfaceBase *surface,<br>
+ uint32_t *present_mode_count,<br>
+ VkPresentModeKHR *present_modes)<br>
+{<br>
+ if (present_modes == NULL) {<br>
+ *present_mode_count = ARRAY_SIZE(available_present_m<wbr>odes);<br>
+ return VK_SUCCESS;<br>
+ }<br>
+<br>
+ *present_mode_count = MIN2(*present_mode_count, ARRAY_SIZE(available_present_m<wbr>odes));<br>
+ typed_memcpy(present_modes, available_present_modes, *present_mode_count);<br>
+<br>
+ if (*present_mode_count < ARRAY_SIZE(available_present_m<wbr>odes))<br>
+ return VK_INCOMPLETE;<br>
+ return VK_SUCCESS;<br>
+}<br>
+<br>
+static VkResult<br>
+wsi_display_image_init(VkDevi<wbr>ce device_h,<br>
+ struct wsi_swapchain *drv_chain,<br>
+ const VkSwapchainCreateInfoKHR *create_info,<br>
+ const VkAllocationCallbacks *allocator,<br>
+ struct wsi_display_image *image)<br>
+{<br>
+ struct wsi_display_swapchain *chain = (struct wsi_display_swapchain *) drv_chain;<br>
+ struct wsi_display *wsi = chain->wsi;<br>
+ VkResult result;<br>
+ int ret;<br>
+ uint32_t image_handle;<br>
+<br>
+ if (chain->base.use_prime_blit)<br>
+ result = wsi_create_prime_image(&chain-<wbr>>base, create_info, &image->base);<br>
+ else<br>
+ result = wsi_create_native_image(&chain<wbr>->base, create_info, &image->base);<br>
+ if (result != VK_SUCCESS)<br>
+ return result;<br>
+<br>
+ ret = drmPrimeFDToHandle(wsi->master<wbr>_fd, image->base.fd, &image_handle);<br>
+<br>
+ close(image->base.fd);<br>
+ image->base.fd = -1;<br>
+<br>
+ if (ret < 0)<br>
+ goto fail_handle;<br>
+<br>
+ image->chain = chain;<br>
+ image->state = wsi_image_idle;<br>
+ image->fb_id = 0;<br>
+<br>
+ /* XXX extract depth and bpp from image somehow */<br>
+ ret = drmModeAddFB(wsi->master_fd, create_info->imageExtent.width<wbr>, create_info->imageExtent.heigh<wbr>t,<br>
+ 24, 32, image->base.row_pitch, image_handle, &image->fb_id);<br>
+<br>
+ if (ret)<br>
+ goto fail_fb;<br>
+<br>
+ return VK_SUCCESS;<br>
+<br>
+fail_fb:<br>
+ /* fall through */<br>
+<br>
+fail_handle:<br>
+ wsi_destroy_image(&chain->bas<wbr>e, &image->base);<br>
+<br>
+ return VK_ERROR_OUT_OF_HOST_MEMORY;<br>
+}<br>
+<br>
+static void<br>
+wsi_display_image_finish(stru<wbr>ct wsi_swapchain *drv_chain,<br>
+ const VkAllocationCallbacks *allocator,<br>
+ struct wsi_display_image *image)<br>
+{<br>
+ struct wsi_display_swapchain *chain = (struct wsi_display_swapchain *) drv_chain;<br>
+<br>
+ wsi_destroy_image(&chain->bas<wbr>e, &image->base);<br>
+}<br>
+<br>
+static VkResult<br>
+wsi_display_swapchain_destroy<wbr>(struct wsi_swapchain *drv_chain,<br>
+ const VkAllocationCallbacks *allocator)<br>
+{<br>
+ struct wsi_display_swapchain *chain = (struct wsi_display_swapchain *) drv_chain;<br>
+<br>
+ for (uint32_t i = 0; i < chain->base.image_count; i++)<br>
+ wsi_display_image_finish(drv_c<wbr>hain, allocator, &chain->images[i]);<br>
+ vk_free(allocator, chain);<br>
+ return VK_SUCCESS;<br>
+}<br>
+<br>
+static struct wsi_image *<br>
+wsi_display_get_wsi_image(str<wbr>uct wsi_swapchain *drv_chain,<br>
+ uint32_t image_index)<br>
+{<br>
+ struct wsi_display_swapchain *chain = (struct wsi_display_swapchain *) drv_chain;<br>
+<br>
+ return &chain->images[image_index].ba<wbr>se;<br>
+}<br>
+<br>
+static void<br>
+wsi_display_idle_old_displayi<wbr>ng(struct wsi_display_image *active_image)<br>
+{<br>
+ struct wsi_display_swapchain *chain = active_image->chain;<br>
+<br>
+ wsi_display_debug("idle everyone but %ld\n", active_image - &(chain->images[0]));<br>
+ for (uint32_t i = 0; i < chain->base.image_count; i++)<br>
+ if (chain->images[i].state == wsi_image_displaying && &chain->images[i] != active_image) {<br>
+ wsi_display_debug("idle %d\n", i);<br>
+ chain->images[i].state = wsi_image_idle;<br>
+ }<br>
+}<br>
+<br>
+static VkResult<br>
+_wsi_display_queue_next(struc<wbr>t wsi_swapchain *drv_chain);<br>
+<br>
+static void<br>
+wsi_display_page_flip_handler<wbr>2(int fd,<br>
+ unsigned int frame,<br>
+ unsigned int sec,<br>
+ unsigned int usec,<br>
+ uint32_t crtc_id,<br>
+ void *data)<br>
+{<br>
+ struct wsi_display_image *image = data;<br>
+<br>
+ wsi_display_debug("image %ld displayed at %d\n", image - &(image->chain->images[0]), frame);<br>
+ image->state = wsi_image_displaying;<br>
+ wsi_display_idle_old_displayi<wbr>ng(image);<br>
+ (void) _wsi_display_queue_next(&(imag<wbr>e->chain->base));<br>
+}<br>
+<br>
+static void wsi_display_page_flip_handler(<wbr>int fd, unsigned int frame,<br>
+ unsigned int sec, unsigned int usec, void *data)<br>
+{<br>
+ wsi_display_page_flip_handler<wbr>2(fd, frame, sec, usec, 0, data);<br>
+}<br>
+<br>
+static drmEventContext event_context = {<br>
+ .version = DRM_EVENT_CONTEXT_VERSION,<br>
+ .page_flip_handler = wsi_display_page_flip_handler,<br>
+#if DRM_EVENT_CONTEXT_VERSION >= 3<br>
+ .page_flip_handler2 = wsi_display_page_flip_handler2<wbr>,<br>
+#endif<br>
+};<br>
+<br>
+static void *<br>
+wsi_display_wait_thread(void *data)<br>
+{<br>
+ struct wsi_display *wsi = data;<br>
+ struct pollfd pollfd = {<br>
+ .fd = wsi->master_fd,<br>
+ .events = POLLIN<br>
+ };<br>
+ int ret;<br>
+<br>
+ pthread_setcanceltype(<wbr>PTHREAD_CANCEL_ASYNCHRONOUS, NULL);<br>
+ for (;;) {<br>
+ ret = poll(&pollfd, 1, -1);<br>
+ if (ret > 0) {<br>
+ pthread_mutex_lock(&wsi-><wbr>wait_mutex);<br>
+ (void) drmHandleEvent(wsi->master_fd, &event_context);<br>
+ pthread_mutex_unlock(&wsi->wa<wbr>it_mutex);<br>
+ pthread_cond_broadcast(&wsi-><wbr>wait_cond);<br>
+ }<br>
+ }<br>
+ return NULL;<br>
+}<br>
+<br>
+static int<br>
+wsi_display_start_wait_thread<wbr>(struct wsi_display *wsi)<br>
+{<br>
+ if (!wsi->wait_thread) {<br>
+ int ret = pthread_create(&wsi->wait_thre<wbr>ad, NULL, wsi_display_wait_thread, wsi);<br>
+ if (ret)<br>
+ return ret;<br>
+ }<br>
+ return 0;<br>
+}<br>
+<br>
+/* call with wait_mutex held */<br>
+static int<br>
+wsi_display_wait_for_event(st<wbr>ruct wsi_display *wsi,<br>
+ uint64_t timeout_ns)<br>
+{<br>
+ int ret;<br>
+<br>
+ ret = wsi_display_start_wait_thread(<wbr>wsi);<br>
+<br>
+ if (ret)<br>
+ return ret;<br>
+<br>
+ struct timespec abs_timeout = {<br>
+ .tv_sec = timeout_ns / ((uint64_t) 1000 * (uint64_t) 1000 * (uint64_t) 1000),<br>
+ .tv_nsec = timeout_ns % ((uint64_t) 1000 * (uint64_t) 1000 * (uint64_t) 1000)<br>
+ };<br>
+<br>
+ ret = pthread_cond_timedwait(&wsi->w<wbr>ait_cond, &wsi->wait_mutex, &abs_timeout);<br>
+<br>
+ wsi_display_debug("%9ld done waiting for event %d\n", pthread_self(), ret);<br>
+ return ret;<br>
+}<br>
+<br>
+static VkResult<br>
+wsi_display_acquire_next_imag<wbr>e(struct wsi_swapchain *drv_chain,<br>
+ uint64_t timeout,<br>
+ VkSemaphore semaphore,<br>
+ uint32_t *image_index)<br>
+{<br>
+ struct wsi_display_swapchain *chain = (struct wsi_display_swapchain *)drv_chain;<br>
+ struct wsi_display *wsi = chain->wsi;<br>
+ int ret = 0;<br>
+ VkResult result = VK_SUCCESS;<br>
+<br>
+ if (timeout != 0 && timeout != UINT64_MAX)<br>
+ timeout += wsi_get_current_monotonic();<br>
+<br>
+ pthread_mutex_lock(&wsi-><wbr>wait_mutex);<br>
+ for (;;) {<br>
+ for (uint32_t i = 0; i < chain->base.image_count; i++) {<br>
+ if (chain->images[i].state == wsi_image_idle) {<br>
+ *image_index = i;<br>
+ wsi_display_debug("image %d available\n", i);<br>
+ chain->images[i].state = wsi_image_drawing;<br>
+ result = VK_SUCCESS;<br>
+ goto done;<br>
+ }<br>
+ wsi_display_debug("image %d state %d\n", i, chain->images[i].state);<br>
+ }<br>
+<br>
+ if (ret == ETIMEDOUT) {<br>
+ result = VK_TIMEOUT;<br>
+ goto done;<br>
+ }<br>
+<br>
+ ret = wsi_display_wait_for_event(wsi<wbr>, timeout);<br>
+<br>
+ if (ret && ret != ETIMEDOUT) {<br>
+ result = VK_ERROR_OUT_OF_DATE_KHR;<br>
+ goto done;<br>
+ }<br>
+ }<br>
+done:<br>
+ pthread_mutex_unlock(&wsi->wa<wbr>it_mutex);<br>
+ return result;<br>
+}<br>
+<br>
+/*<br>
+ * Check whether there are any other connectors driven by this crtc<br>
+ */<br>
+static bool<br>
+wsi_display_crtc_solo(struct wsi_display *wsi,<br>
+ drmModeResPtr mode_res,<br>
+ drmModeConnectorPtr connector,<br>
+ uint32_t crtc_id)<br>
+{<br>
+ int c, e;<br>
+<br>
+ /* See if any other connectors share the same encoder */<br>
+ for (c = 0; c < mode_res->count_connectors; c++) {<br>
+ if (mode_res->connectors[c] == connector->connector_id)<br>
+ continue;<br>
+<br>
+ drmModeConnectorPtr other_connector = drmModeGetConnector(wsi->maste<wbr>r_fd, mode_res->connectors[c]);<br>
+ if (other_connector) {<br>
+ bool match = (other_connector->encoder_id == connector->encoder_id);<br>
+ drmModeFreeConnector(other_co<wbr>nnector);<br>
+ if (match)<br>
+ return false;<br>
+ }<br>
+ }<br>
+<br>
+ /* See if any other encoders share the same crtc */<br>
+ for (e = 0; e < mode_res->count_encoders; e++) {<br>
+ if (mode_res->encoders[e] == connector->encoder_id)<br>
+ continue;<br>
+<br>
+ drmModeEncoderPtr other_encoder = drmModeGetEncoder(wsi->master_<wbr>fd, mode_res->encoders[e]);<br>
+ if (other_encoder) {<br>
+ bool match = (other_encoder->crtc_id == crtc_id);<br>
+ drmModeFreeEncoder(other_enco<wbr>der);<br>
+ if (match)<br>
+ return false;<br>
+ }<br>
+ }<br>
+ return true;<br>
+}<br>
+<br>
+/*<br>
+ * Pick a suitable CRTC to drive this connector. Prefer a CRTC which is<br>
+ * currently driving this connector and not any others. Settle for a CRTC<br>
+ * which is currently idle.<br>
+ */<br>
+static uint32_t<br>
+wsi_display_select_crtc(struc<wbr>t wsi_display_connector *connector,<br>
+ drmModeResPtr mode_res,<br>
+ drmModeConnectorPtr drm_connector)<br>
+{<br>
+ struct wsi_display *wsi = connector->wsi;<br>
+ int c;<br>
+ uint32_t crtc_id;<br>
+<br>
+ /* See what CRTC is currently driving this connector */<br>
+ if (drm_connector->encoder_id) {<br>
+ drmModeEncoderPtr encoder = drmModeGetEncoder(wsi->master_<wbr>fd, drm_connector->encoder_id);<br>
+ if (encoder) {<br>
+ crtc_id = encoder->crtc_id;<br>
+ drmModeFreeEncoder(encoder);<br>
+ if (crtc_id) {<br>
+ if (wsi_display_crtc_solo(wsi, mode_res, drm_connector, crtc_id))<br>
+ return crtc_id;<br>
+ }<br>
+ }<br>
+ }<br>
+ crtc_id = 0;<br>
+ for (c = 0; crtc_id == 0 && c < mode_res->count_crtcs; c++) {<br>
+ drmModeCrtcPtr crtc = drmModeGetCrtc(wsi->master_fd, mode_res->crtcs[c]);<br>
+ if (crtc && crtc->buffer_id == 0)<br>
+ crtc_id = crtc->crtc_id;<br>
+ drmModeFreeCrtc(crtc);<br>
+ }<br>
+ return crtc_id;<br>
+}<br>
+<br>
+static VkResult<br>
+wsi_display_setup_connector(w<wbr>si_display_connector *connector,<br>
+ wsi_display_mode *display_mode)<br>
+{<br>
+ struct wsi_display *wsi = connector->wsi;<br>
+ drmModeModeInfoPtr drm_mode;<br>
+ drmModeConnectorPtr drm_connector;<br>
+ drmModeResPtr mode_res;<br>
+ VkResult result;<br>
+ int m;<br>
+<br>
+ if (connector->current_mode == display_mode && connector->crtc_id)<br>
+ return VK_SUCCESS;<br>
+<br>
+ mode_res = drmModeGetResources(wsi->maste<wbr>r_fd);<br>
+ if (!mode_res) {<br>
+ result = VK_ERROR_INITIALIZATION_FAILED<wbr>;<br>
+ goto bail;<br>
+ }<br>
+<br>
+ drm_connector = drmModeGetConnectorCurrent(wsi<wbr>->master_fd, connector->id);<br>
+ if (!drm_connector) {<br>
+ result = VK_ERROR_INITIALIZATION_FAILED<wbr>;<br>
+ goto bail_mode_res;<br>
+ }<br>
+<br>
+ /* Pick a CRTC if we don't have one */<br>
+ if (!connector->crtc_id) {<br>
+ connector->crtc_id = wsi_display_select_crtc(connec<wbr>tor, mode_res, drm_connector);<br>
+ if (!connector->crtc_id) {<br>
+ result = VK_ERROR_OUT_OF_DATE_KHR;<br>
+ goto bail_connector;<br>
+ }<br>
+ }<br>
+<br>
+ if (connector->current_mode != display_mode) {<br>
+<br>
+ /* Find the drm mode cooresponding to the requested VkDisplayMode */<br>
+ drm_mode = NULL;<br>
+ for (m = 0; m < drm_connector->count_modes; m++) {<br>
+ drm_mode = &drm_connector->modes[m];<br>
+ if (wsi_display_mode_matches_drm(<wbr>display_mode, drm_mode))<br>
+ break;<br>
+ drm_mode = NULL;<br>
+ }<br>
+<br>
+ if (!drm_mode) {<br>
+ result = VK_ERROR_OUT_OF_DATE_KHR;<br>
+ goto bail_connector;<br>
+ }<br>
+<br>
+ connector->current_mode = display_mode;<br>
+ connector->current_drm_mode = *drm_mode;<br>
+ }<br>
+<br>
+ result = VK_SUCCESS;<br>
+<br>
+bail_connector:<br>
+ drmModeFreeConnector(drm_conn<wbr>ector);<br>
+bail_mode_res:<br>
+ drmModeFreeResources(mode_<wbr>res);<br>
+bail:<br>
+ return result;<br>
+<br>
+}<br>
+<br>
+/*<br>
+ * Check to see if the kernel has no flip queued and if there's an image<br>
+ * waiting to be displayed.<br>
+ */<br>
+static VkResult<br>
+_wsi_display_queue_next(struc<wbr>t wsi_swapchain *drv_chain)<br>
+{<br>
+ struct wsi_display_swapchain *chain = (struct wsi_display_swapchain *) drv_chain;<br>
+ struct wsi_display *wsi = chain->wsi;<br>
+ uint32_t i;<br>
+ struct wsi_display_image *image = NULL;<br>
+ VkIcdSurfaceDisplay *surface = chain->surface;<br>
+ wsi_display_mode *display_mode = wsi_display_mode_from_handle(s<wbr>urface->displayMode);<br>
+ wsi_display_connector *connector = display_mode->connector;<br>
+ int ret;<br>
+ VkResult result;<br>
+<br>
+ if (wsi->master_fd < 0)<br>
+ return VK_ERROR_INITIALIZATION_FAILED<wbr>;<br>
+<br>
+ if (display_mode != connector->current_mode)<br>
+ connector->active = false;<br>
+<br>
+ for (;;) {<br>
+ /* Check to see if there is an image to display, or if some image is already queued */<br>
+<br>
+ for (i = 0; i < chain->base.image_count; i++) {<br>
+ struct wsi_display_image *tmp_image = &chain->images[i];<br>
+<br>
+ switch (tmp_image->state) {<br>
+ case wsi_image_flipping:<br>
+ /* already flipping, don't send another to the kernel yet */<br>
+ return VK_SUCCESS;<br>
+ case wsi_image_queued:<br>
+ /* find the oldest queued */<br>
+ if (!image || tmp_image->flip_sequence < image->flip_sequence)<br>
+ image = tmp_image;<br>
+ break;<br>
+ default:<br>
+ break;<br>
+ }<br>
+ }<br>
+<br>
+ if (!image)<br>
+ return VK_SUCCESS;<br>
+<br>
+ if (connector->active) {<br>
+ ret = drmModePageFlip(wsi->master_fd<wbr>, connector->crtc_id, image->fb_id,<br>
+ DRM_MODE_PAGE_FLIP_EVENT, image);<br>
+ if (ret == 0) {<br>
+ image->state = wsi_image_flipping;<br>
+ return VK_SUCCESS;<br>
+ }<br>
+ wsi_display_debug("page flip err %d %s\n", ret, strerror(-ret));<br>
+ } else<br>
+ ret = -EINVAL;<br>
+<br>
+ if (ret) {<br>
+ switch(-ret) {<br>
+ case EINVAL:<br>
+<br>
+ result = wsi_display_setup_connector(co<wbr>nnector, display_mode);<br>
+<br>
+ if (result != VK_SUCCESS) {<br>
+ image->state = wsi_image_idle;<br>
+ return result;<br>
+ }<br>
+<br>
+ /* XXX allow setting of position */<br>
+<br>
+ ret = drmModeSetCrtc(wsi->master_fd, connector->crtc_id, image->fb_id, 0, 0,<br>
+ &connector->id, 1, &connector->current_drm_mode);<br>
+<br>
+ if (ret == 0) {<br>
+ image->state = wsi_image_displaying;<br>
+ wsi_display_idle_old_displayi<wbr>ng(image);<br>
+ connector->active = true;<br>
+ return VK_SUCCESS;<br>
+ }<br>
+ break;<br>
+ case EACCES:<br>
+ usleep(1000 * 1000);<br>
+ connector->active = false;<br>
+ break;<br>
+ default:<br>
+ connector->active = false;<br>
+ image->state = wsi_image_idle;<br>
+ return VK_ERROR_OUT_OF_DATE_KHR;<br>
+ }<br>
+ }<br>
+ }<br>
+}<br>
+<br>
+static VkResult<br>
+wsi_display_queue_present(str<wbr>uct wsi_swapchain *drv_chain,<br>
+ uint32_t image_index,<br>
+ const VkPresentRegionKHR *damage)<br>
+{<br>
+ struct wsi_display_swapchain *chain = (struct wsi_display_swapchain *) drv_chain;<br>
+ struct wsi_display *wsi = chain->wsi;<br>
+ struct wsi_display_image *image = &chain->images[image_index];<br>
+ VkResult result;<br>
+<br>
+ assert(image->state == wsi_image_drawing);<br>
+ wsi_display_debug("present %d\n", image_index);<br>
+<br>
+ pthread_mutex_lock(&wsi-><wbr>wait_mutex);<br>
+<br>
+ image->flip_sequence = ++chain->flip_sequence;<br>
+ image->state = wsi_image_queued;<br>
+<br>
+ result = _wsi_display_queue_next(drv_ch<wbr>ain);<br>
+<br>
+ pthread_mutex_unlock(&wsi->wa<wbr>it_mutex);<br>
+<br>
+ return result;<br>
+}<br>
+<br>
+static VkResult<br>
+wsi_display_surface_create_sw<wbr>apchain(VkIcdSurfaceBase *icd_surface,<br>
+ VkDevice device,<br>
+ struct wsi_device *wsi_device,<br>
+ int local_fd,<br>
+ const VkSwapchainCreateInfoKHR *create_info,<br>
+ const VkAllocationCallbacks *allocator,<br>
+ struct wsi_swapchain **swapchain_out)<br>
+{<br>
+ struct wsi_display *wsi = (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLA<wbr>TFORM_DISPLAY];<br>
+ VkResult result;<br>
+<br>
+ assert(create_info->sType == VK_STRUCTURE_TYPE_SWAPCHAIN_CR<wbr>EATE_INFO_KHR);<br>
+<br>
+ struct wsi_display_swapchain *chain;<br>
+ const unsigned num_images = create_info->minImageCount;<br>
+ size_t size = sizeof(*chain) + num_images * sizeof(chain->images[0]);<br>
+<br>
+ chain = vk_alloc(allocator, size, 8,<br>
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJ<wbr>ECT);<br>
+<br>
+ if (chain == NULL)<br>
+ return VK_ERROR_OUT_OF_HOST_MEMORY;<br>
+<br>
+ result = wsi_swapchain_init(wsi_device, &chain->base, device,<br>
+ create_info, allocator);<br>
+<br>
+ chain->base.destroy = wsi_display_swapchain_destroy;<br>
+ chain->base.get_wsi_image = wsi_display_get_wsi_image;<br>
+ chain->base.acquire_next_<wbr>image = wsi_display_acquire_next_image<wbr>;<br>
+ chain->base.queue_present = wsi_display_queue_present;<br>
+ chain->base.present_mode = create_info->presentMode;<br>
+ chain->base.image_count = num_images;<br>
+<br>
+ chain->wsi = wsi;<br>
+<br>
+ chain->surface = (VkIcdSurfaceDisplay *) icd_surface;<br>
+<br>
+ for (uint32_t image = 0; image < chain->base.image_count; image++) {<br>
+ result = wsi_display_image_init(device, &chain->base, create_info, allocator,<br>
+ &chain->images[image]);<br>
+ if (result != VK_SUCCESS)<br>
+ goto fail_init_images;<br>
+ }<br>
+<br>
+ *swapchain_out = &chain->base;<br>
+<br>
+ return VK_SUCCESS;<br>
+<br>
+fail_init_images:<br>
+ return result;<br>
+}<br>
+<br>
+VkResult<br>
+wsi_display_init_wsi(struct wsi_device *wsi_device,<br>
+ const VkAllocationCallbacks *alloc,<br>
+ VkPhysicalDevice physical_device,<br>
+ int device_fd)<br>
+{<br>
+ struct wsi_display *wsi;<br>
+ VkResult result;<br>
+<br>
+ wsi = vk_alloc(alloc, sizeof(*wsi), 8,<br>
+ VK_SYSTEM_ALLOCATION_SCOPE_IN<wbr>STANCE);<br>
+ if (!wsi) {<br>
+ result = VK_ERROR_OUT_OF_HOST_MEMORY;<br>
+ goto fail;<br>
+ }<br>
+ memset(wsi, '\0', sizeof (*wsi));<br>
+<br>
+ wsi->master_fd = -1;<br>
+ if (drmGetNodeTypeFromFd(device_f<wbr>d) == DRM_NODE_PRIMARY)<br>
+ wsi->master_fd = device_fd;<br>
+ wsi->render_fd = device_fd;<br>
+<br>
+ pthread_mutex_init(&wsi-><wbr>wait_mutex, NULL);<br>
+ wsi->physical_device = physical_device;<br>
+ wsi->alloc = alloc;<br>
+<br>
+ LIST_INITHEAD(&wsi->display_m<wbr>odes);<br>
+ LIST_INITHEAD(&wsi->connector<wbr>s);<br>
+<br>
+ pthread_condattr_t condattr;<br>
+ int ret;<br>
+<br>
+ ret = pthread_mutex_init(&wsi->wait_<wbr>mutex, NULL);<br>
+ if (ret) {<br>
+ result = VK_ERROR_OUT_OF_HOST_MEMORY;<br>
+ goto fail_mutex;<br>
+ }<br>
+<br>
+ ret = pthread_condattr_init(&condatt<wbr>r);<br>
+ if (ret) {<br>
+ result = VK_ERROR_OUT_OF_HOST_MEMORY;<br>
+ goto fail_condattr;<br>
+ }<br>
+<br>
+ ret = pthread_condattr_setclock(&con<wbr>dattr, CLOCK_MONOTONIC);<br>
+ if (ret) {<br>
+ result = VK_ERROR_OUT_OF_HOST_MEMORY;<br>
+ goto fail_setclock;<br>
+ }<br>
+<br>
+ ret = pthread_cond_init(&wsi->wait_c<wbr>ond, &condattr);<br>
+ if (ret) {<br>
+ result = VK_ERROR_OUT_OF_HOST_MEMORY;<br>
+ goto fail_cond;<br>
+ }<br>
+<br>
+ pthread_condattr_destroy(&con<wbr>dattr);<br>
+<br>
+ wsi->base.get_support = wsi_display_surface_get_suppor<wbr>t;<br>
+ wsi->base.get_capabilities = wsi_display_surface_get_capabi<wbr>lities;<br>
+ wsi->base.get_capabilities2 = wsi_display_surface_get_capabi<wbr>lities2;<br>
+ wsi->base.get_formats = wsi_display_surface_get_format<wbr>s;<br>
+ wsi->base.get_formats2 = wsi_display_surface_get_format<wbr>s2;<br>
+ wsi->base.get_present_modes = wsi_display_surface_get_presen<wbr>t_modes;<br>
+ wsi->base.create_swapchain = wsi_display_surface_create_swa<wbr>pchain;<br>
+<br>
+ wsi_device->wsi[VK_ICD_WSI_PL<wbr>ATFORM_DISPLAY] = &wsi->base;<br>
+<br>
+ return VK_SUCCESS;<br>
+<br>
+fail_cond:<br>
+fail_setclock:<br>
+ pthread_condattr_destroy(&con<wbr>dattr);<br>
+fail_condattr:<br>
+ pthread_mutex_destroy(&wsi->w<wbr>ait_mutex);<br>
+fail_mutex:<br>
+ vk_free(alloc, wsi);<br>
+fail:<br>
+ return result;<br>
+}<br>
+<br>
+void<br>
+wsi_display_finish_wsi(struct wsi_device *wsi_device,<br>
+ const VkAllocationCallbacks *alloc)<br>
+{<br>
+ struct wsi_display *wsi = (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLA<wbr>TFORM_DISPLAY];<br>
+<br>
+ if (wsi) {<br>
+<br>
+ struct wsi_display_connector *connector, *connector_storage;<br>
+ LIST_FOR_EACH_ENTRY_SAFE(conne<wbr>ctor, connector_storage, &wsi->connectors, list) {<br>
+ vk_free(wsi->alloc, connector);<br>
+ }<br>
+<br>
+ struct wsi_display_mode *mode, *mode_storage;<br>
+ LIST_FOR_EACH_ENTRY_SAFE(mode, mode_storage, &wsi->display_modes, list) {<br>
+ vk_free(wsi->alloc, mode);<br>
+ }<br>
+<br>
+ pthread_mutex_lock(&wsi->wait_<wbr>mutex);<br>
+ if (wsi->wait_thread) {<br>
+ pthread_cancel(wsi->wait_thre<wbr>ad);<br>
+ pthread_join(wsi->wait_<wbr>thread, NULL);<br>
+ }<br>
+ pthread_mutex_unlock(&wsi->wai<wbr>t_mutex);<br>
+ pthread_mutex_destroy(&wsi->wa<wbr>it_mutex);<br>
+ pthread_cond_destroy(&wsi->wai<wbr>t_cond);<br>
+<br>
+ vk_free(alloc, wsi);<br>
+ }<br>
+}<br>
diff --git a/src/vulkan/wsi/wsi_common_di<wbr>splay.h b/src/vulkan/wsi/wsi_common_di<wbr>splay.h<br>
new file mode 100644<br>
index 00000000000..b414a226293<br>
--- /dev/null<br>
+++ b/src/vulkan/wsi/wsi_common_di<wbr>splay.h<br>
@@ -0,0 +1,72 @@<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>
+#ifndef WSI_COMMON_DISPLAY_H<br>
+#define WSI_COMMON_DISPLAY_H<br>
+<br>
+#include "wsi_common.h"<br>
+#include <xf86drm.h><br>
+#include <xf86drmMode.h><br>
+<br>
+#define typed_memcpy(dest, src, count) ({ \<br>
+ STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \<br>
+ memcpy((dest), (src), (count) * sizeof(*(src))); \<br>
+})<br>
+<br>
+VkResult<br>
+wsi_display_get_physical_devi<wbr>ce_display_properties(VkPhysic<wbr>alDevice physical_device,<br>
+ struct wsi_device *wsi_device,<br>
+ uint32_t *property_count,<br>
+ VkDisplayPropertiesKHR *properties);<br>
+VkResult<br>
+wsi_display_get_physical_devi<wbr>ce_display_plane_properties(<wbr>VkPhysicalDevice physical_device,<br>
+ struct wsi_device *wsi_device,<br>
+ uint32_t *property_count,<br>
+ VkDisplayPlanePropertiesKHR *properties);<br>
+<br>
+VkResult<br>
+wsi_display_get_display_plane<wbr>_supported_displays(VkPhysical<wbr>Device physical_device,<br>
+ struct wsi_device *wsi_device,<br>
+ uint32_t plane_index,<br>
+ uint32_t *display_count,<br>
+ VkDisplayKHR *displays);<br>
+VkResult<br>
+wsi_display_get_display_mode_<wbr>properties(VkPhysicalDevice physical_device,<br>
+ struct wsi_device *wsi_device,<br>
+ VkDisplayKHR display,<br>
+ uint32_t *property_count,<br>
+ VkDisplayModePropertiesKHR *properties);<br>
+<br>
+VkResult<br>
+wsi_get_display_plane_capabil<wbr>ities(VkPhysicalDevice physical_device,<br>
+ struct wsi_device *wsi_device,<br>
+ VkDisplayModeKHR mode_khr,<br>
+ uint32_t plane_index,<br>
+ VkDisplayPlaneCapabilitiesKHR *capabilities);<br>
+<br>
+VkResult<br>
+wsi_create_display_surface(Vk<wbr>Instance instance,<br>
+ const VkAllocationCallbacks *pAllocator,<br>
+ const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,<br>
+ VkSurfaceKHR *pSurface);<br>
+<br>
+#endif<br>
diff --git a/src/vulkan/wsi/wsi_common_pr<wbr>ivate.h b/src/vulkan/wsi/wsi_common_pr<wbr>ivate.h<br>
index 503b2a015dc..d38d2efa116 100644<br>
--- a/src/vulkan/wsi/wsi_common_pr<wbr>ivate.h<br>
+++ b/src/vulkan/wsi/wsi_common_pr<wbr>ivate.h<br>
@@ -135,6 +135,16 @@ void wsi_wl_finish_wsi(struct wsi_device *wsi_device,<br>
const VkAllocationCallbacks *alloc);<br>
<br>
<br>
+VkResult<br>
+wsi_display_init_wsi(struct wsi_device *wsi_device,<br>
+ const VkAllocationCallbacks *alloc,<br>
+ VkPhysicalDevice physical_device,<br>
+ int device_fd);<br>
+<br>
+void<br>
+wsi_display_finish_wsi(struct wsi_device *wsi_device,<br>
+ const VkAllocationCallbacks *alloc);<br>
+<br>
#define WSI_DEFINE_NONDISP_HANDLE_CAST<wbr>S(__wsi_type, __VkType) \<br>
\<br>
static inline struct __wsi_type * \<br>
<span class="gmail-m_-8728956912167375268gmail-HOEnZb"><font color="#888888">--<br>
2.15.1<br>
<br>
______________________________<wbr>_________________<br>
dri-devel mailing list<br>
<a href="mailto:dri-devel@lists.freedesktop.org" target="_blank">dri-devel@lists.freedesktop.or<wbr>g</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>