c869ba8553448e1494a49757e9d5f7b9eef66045 — Drew DeVault 3 months ago c6cb9b1 drm-lease
Implement VK_EXT_acquire_wl_display
M include/vulkan/vk_platform.h => include/vulkan/vk_platform.h +6 -0
@@ 85,6 85,12 @@ #endif
  #endif // !defined(VK_NO_STDINT_H)
  
+ #ifdef VK_USE_PLATFORM_WAYLAND_KHR
+     // Forward declared for VK_EXT_acquire_wl_display
+     struct zwp_drm_lease_manager_v1;
+     struct zwp_drm_lease_connector_v1;
+ #endif // VK_USE_PLATFORM_WAYLAND_KHR
+ 
  #ifdef __cplusplus
  } // extern "C"
  #endif // __cplusplus

M include/vulkan/vulkan_core.h => include/vulkan/vulkan_core.h +47 -1
@@ 43,7 43,7 @@ #define VK_VERSION_MINOR(version) (((uint32_t)(version) >> 12) & 0x3ff)
  #define VK_VERSION_PATCH(version) ((uint32_t)(version) & 0xfff)
  // Version of this file
- #define VK_HEADER_VERSION 113
+ #define VK_HEADER_VERSION 114
  
  
  #define VK_NULL_HANDLE 0


@@ 351,6 351,10 @@ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT = 1000102000,
      VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT = 1000102001,
      VK_STRUCTURE_TYPE_HDR_METADATA_EXT = 1000105000,
+     VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR = 1000108000,
+     VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR = 1000108001,
+     VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR = 1000108002,
+     VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO_KHR = 1000108003,
      VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2_KHR = 1000109000,
      VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR = 1000109001,
      VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2_KHR = 1000109002,


@@ 1709,6 1713,11 @@ } VkDescriptorPoolCreateFlagBits;
  typedef VkFlags VkDescriptorPoolCreateFlags;
  typedef VkFlags VkDescriptorPoolResetFlags;
+ 
+ typedef enum VkFramebufferCreateFlagBits {
+     VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR = 0x00000001,
+     VK_FRAMEBUFFER_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+ } VkFramebufferCreateFlagBits;
  typedef VkFlags VkFramebufferCreateFlags;
  typedef VkFlags VkRenderPassCreateFlags;
  


@@ 5602,6 5611,43 @@ #endif
  
  
+ #define VK_KHR_imageless_framebuffer 1
+ #define VK_KHR_IMAGELESS_FRAMEBUFFER_SPEC_VERSION 1
+ #define VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME "VK_KHR_imageless_framebuffer"
+ typedef struct VkPhysicalDeviceImagelessFramebufferFeaturesKHR {
+     VkStructureType    sType;
+     void*              pNext;
+     VkBool32           imagelessFramebuffer;
+ } VkPhysicalDeviceImagelessFramebufferFeaturesKHR;
+ 
+ typedef struct VkFramebufferAttachmentImageInfoKHR {
+     VkStructureType       sType;
+     const void*           pNext;
+     VkImageCreateFlags    flags;
+     VkImageUsageFlags     usage;
+     uint32_t              width;
+     uint32_t              height;
+     uint32_t              layerCount;
+     uint32_t              viewFormatCount;
+     const VkFormat*       pViewFormats;
+ } VkFramebufferAttachmentImageInfoKHR;
+ 
+ typedef struct VkFramebufferAttachmentsCreateInfoKHR {
+     VkStructureType                               sType;
+     const void*                                   pNext;
+     uint32_t                                      attachmentImageInfoCount;
+     const VkFramebufferAttachmentImageInfoKHR*    pAttachmentImageInfos;
+ } VkFramebufferAttachmentsCreateInfoKHR;
+ 
+ typedef struct VkRenderPassAttachmentBeginInfoKHR {
+     VkStructureType       sType;
+     const void*           pNext;
+     uint32_t              attachmentCount;
+     const VkImageView*    pAttachments;
+ } VkRenderPassAttachmentBeginInfoKHR;
+ 
+ 
+ 
  #define VK_KHR_create_renderpass2 1
  #define VK_KHR_CREATE_RENDERPASS_2_SPEC_VERSION 1
  #define VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME "VK_KHR_create_renderpass2"

M include/vulkan/vulkan_wayland.h => include/vulkan/vulkan_wayland.h +20 -0
@@ 56,6 56,26 @@ struct wl_display*                          display);
  #endif
  
+ 
+ #define VK_EXT_acquire_wl_display 1
+ #define VK_EXT_ACQUIRE_WL_DISPLAY_SPEC_VERSION 1
+ #define VK_EXT_ACQUIRE_WL_DISPLAY_EXTENSION_NAME "VK_EXT_acquire_wl_display"
+ typedef struct VkWaylandLeaseConnectorEXT {
+     struct zwp_drm_lease_connector_v1*    pConnectorIn;
+     VkDisplayKHR                          displayOut;
+ } VkWaylandLeaseConnectorEXT;
+ 
+ typedef VkResult (VKAPI_PTR *PFN_vkAcquireWaylandDisplayEXT)(VkPhysicalDevice physicalDevice, struct wl_display* display, struct zwp_drm_lease_manager_v1* manager, int nConnectors, VkWaylandLeaseConnectorEXT* pConnectors);
+ 
+ #ifndef VK_NO_PROTOTYPES
+ VKAPI_ATTR VkResult VKAPI_CALL vkAcquireWaylandDisplayEXT(
+     VkPhysicalDevice                            physicalDevice,
+     struct wl_display*                          display,
+     struct zwp_drm_lease_manager_v1*            manager,
+     int                                         nConnectors,
+     VkWaylandLeaseConnectorEXT*                 pConnectors);
+ #endif
+ 
  #ifdef __cplusplus
  }
  #endif

M meson.build => meson.build +7 -0
@@ 292,6 292,13 @@ with_xlib_lease = _xlib_lease == 'true'
  endif
  
+ _wl_lease = get_option('wl-lease')
+ if _wl_lease == 'auto'
+   with_wl_lease = with_platform_wayland and with_platform_drm
+ else
+   with_wl_lease = _wl_lease == 'true'
+ endif
+ 
  with_glx = get_option('glx')
  if with_glx == 'auto'
    if with_dri

M meson_options.txt => meson_options.txt +7 -0
@@ 328,6 328,13 @@ description : 'Enable VK_EXT_acquire_xlib_display.'
  )
  option(
+   'wl-lease',
+   type : 'combo',
+   value : 'auto',
+   choices : ['auto', 'true', 'false'],
+   description : 'Enable VK_EXT_acquire_wl_display.'
+ )
+ option(
    'glx-direct',
    type : 'boolean',
    value : true,

M src/amd/vulkan/radv_extensions.py => src/amd/vulkan/radv_extensions.py +1 -0
@@ 100,6 100,7 @@ Extension('VK_KHR_8bit_storage',                      1, 'device->rad_info.chip_class >= GFX8'),
      Extension('VK_EXT_direct_mode_display',               1, 'VK_USE_PLATFORM_DISPLAY_KHR'),
      Extension('VK_EXT_acquire_xlib_display',              1, 'VK_USE_PLATFORM_XLIB_XRANDR_EXT'),
+     Extension('VK_EXT_acquire_wl_display',                1, 'VK_USE_PLATFORM_WAYLAND_KHR'),
      Extension('VK_EXT_buffer_device_address',             1, True),
      Extension('VK_EXT_calibrated_timestamps',             1, True),
      Extension('VK_EXT_conditional_rendering',             1, True),

M src/amd/vulkan/radv_wsi_display.c => src/amd/vulkan/radv_wsi_display.c +22 -0
@@ 348,3 348,25 @@ value);
  }
  
+ #ifdef VK_USE_PLATFORM_WAYLAND_KHR
+ 
+ /* VK_EXT_acquire_wl_display */
+ 
+ VkResult
+ radv_AcquireWaylandDisplayEXT(VkPhysicalDevice                 physical_device,
+ 			      struct wl_display*               display,
+ 			      struct zwp_drm_lease_manager_v1* manager,
+ 			      int                              nConnectors,
+ 			      VkWaylandLeaseConnectorEXT*      pConnectors)
+ {
+ 	RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
+ 
+ 	return wsi_acquire_wl_display(physical_device,
+ 				      &pdevice->wsi_device,
+ 				      display,
+ 				      manager,
+ 				      nConnectors,
+ 				      pConnectors);
+ }
+ 
+ #endif /* VK_USE_PLATFORM_WAYLAND_KHR */

M src/vulkan/meson.build => src/vulkan/meson.build +1 -2
@@ 40,7 40,7 @@ vulkan_wsi_list += ['xcb', 'x11']
  endif
  if with_platform_wayland
-   vulkan_wsi_args += ['-DVK_USE_PLATFORM_WAYLAND_KHR']
+   vulkan_wsi_args += ['-DVK_USE_PLATFORM_WAYLAND_KHR', '-DVK_USE_PLATFORM_WAYLAND']
    vulkan_wsi_deps += dep_wayland_client
    vulkan_wsi_list += ['wayland']
  endif


@@ 55,7 55,6 @@ vulkan_wsi_list += ['xlib_xrandr']
  endif
  
- 
  subdir('util')
  subdir('wsi')
  if get_option('vulkan-overlay-layer')

M src/vulkan/registry/vk.xml => src/vulkan/registry/vk.xml +76 -5
@@ 127,6 127,8 @@ <type requires="X11/extensions/Xrandr.h" name="RROutput"/>
          <type requires="wayland-client.h" name="wl_display"/>
          <type requires="wayland-client.h" name="wl_surface"/>
+         <type name="zwp_drm_lease_manager_v1"/>
+         <type name="zwp_drm_lease_connector_v1"/>
          <type requires="windows.h" name="HINSTANCE"/>
          <type requires="windows.h" name="HWND"/>
          <type requires="windows.h" name="HMONITOR"/>


@@ 154,7 156,7 @@ <type category="define">// Vulkan 1.1 version number
  #define <name>VK_API_VERSION_1_1</name> <type>VK_MAKE_VERSION</type>(1, 1, 0)// Patch version should always be set to 0</type>
          <type category="define">// Version of this file
- #define <name>VK_HEADER_VERSION</name> 113</type>
+ #define <name>VK_HEADER_VERSION</name> 114</type>
  
          <type category="define">
  #define <name>VK_DEFINE_HANDLE</name>(object) typedef struct object##_T* object;</type>


@@ 199,7 201,7 @@ <type name="int"/>
  
              <comment>Bitmask types</comment>
-         <type                                             category="bitmask">typedef <type>VkFlags</type> <name>VkFramebufferCreateFlags</name>;</type>
+         <type requires="VkFramebufferCreateFlagBits"      category="bitmask">typedef <type>VkFlags</type> <name>VkFramebufferCreateFlags</name>;</type>
          <type                                             category="bitmask">typedef <type>VkFlags</type> <name>VkQueryPoolCreateFlags</name>;</type>
          <type                                             category="bitmask">typedef <type>VkFlags</type> <name>VkRenderPassCreateFlags</name>;</type>
          <type requires="VkSamplerCreateFlagBits"          category="bitmask">typedef <type>VkFlags</type> <name>VkSamplerCreateFlags</name>;</type>


@@ 3808,6 3810,34 @@ <member><type>VkBool32</type>                         <name>filterCubic</name></member> <!-- The combinations of format, image type (and image view type if provided) can be filtered with VK_FILTER_CUBIC_EXT -->
              <member><type>VkBool32</type>                         <name>filterCubicMinmax</name> </member> <!-- The combination of format, image type (and image view type if provided) can be filtered with VK_FILTER_CUBIC_EXT and ReductionMode of Min or Max -->
          </type>
+         <type category="struct" name="VkPhysicalDeviceImagelessFramebufferFeaturesKHR" structextends="VkPhysicalDeviceFeatures2,VkDeviceCreateInfo">
+             <member values="VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR"><type>VkStructureType</type> <name>sType</name></member>
+             <member><type>void</type>*                                    <name>pNext</name></member>
+             <member><type>VkBool32</type>                                 <name>imagelessFramebuffer</name></member>
+         </type>
+         <type category="struct" name="VkFramebufferAttachmentsCreateInfoKHR" structextends="VkFramebufferCreateInfo">
+             <member values="VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR"><type>VkStructureType</type> <name>sType</name></member>
+             <member>const <type>void</type>*                              <name>pNext</name></member>
+             <member optional="true"><type>uint32_t</type>                 <name>attachmentImageInfoCount</name></member>
+             <member len="attachmentImageInfoCount">const <type>VkFramebufferAttachmentImageInfoKHR</type>* <name>pAttachmentImageInfos</name></member>
+         </type>
+         <type category="struct" name="VkFramebufferAttachmentImageInfoKHR">
+             <member values="VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR"><type>VkStructureType</type> <name>sType</name></member>
+             <member>const <type>void</type>*                              <name>pNext</name></member>
+             <member optional="true"><type>VkImageCreateFlags</type>       <name>flags</name><comment>Image creation flags</comment></member>
+             <member><type>VkImageUsageFlags</type>                        <name>usage</name><comment>Image usage flags</comment></member>
+             <member><type>uint32_t</type>                                 <name>width</name></member>
+             <member><type>uint32_t</type>                                 <name>height</name></member>
+             <member><type>uint32_t</type>                                 <name>layerCount</name></member>
+             <member optional="true"><type>uint32_t</type>                 <name>viewFormatCount</name></member>
+             <member len="viewFormatCount">const <type>VkFormat</type>*    <name>pViewFormats</name></member>
+         </type>
+         <type category="struct" name="VkRenderPassAttachmentBeginInfoKHR" structextends="VkRenderPassBeginInfo">
+             <member values="VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO_KHR"><type>VkStructureType</type> <name>sType</name></member>
+             <member>const <type>void</type>*                              <name>pNext</name></member>             <!-- Pointer to next structure -->
+             <member optional="true"><type>uint32_t</type>                 <name>attachmentCount</name></member>
+             <member len="attachmentCount">const <type>VkImageView</type>* <name>pAttachments</name></member>
+         </type>
          <type category="struct" name="VkPhysicalDeviceCooperativeMatrixFeaturesNV" structextends="VkPhysicalDeviceFeatures2,VkDeviceCreateInfo">
              <member values="VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_NV"><type>VkStructureType</type> <name>sType</name></member>
              <member><type>void</type>*                               <name>pNext</name></member>


@@ 3982,6 4012,10 @@ <member><type>VkDeviceSize</type>                       <name>uniformTexelBufferOffsetAlignmentBytes</name></member>
              <member><type>VkBool32</type>                           <name>uniformTexelBufferOffsetSingleTexelAlignment</name></member>
          </type>
+ 		<type category="struct" name="VkWaylandLeaseConnectorEXT">
+ 			<member>struct <type>zwp_drm_lease_connector_v1</type>* <name>pConnectorIn</name></member>
+ 			<member><type>VkDisplayKHR</type> <name>displayOut</name></member>
+ 		</type>
      </types>
  
      <comment>Vulkan enumerant (token) definitions</comment>


@@ 5191,6 5225,8 @@ <enum value="1"     name="VK_MEMORY_OVERALLOCATION_BEHAVIOR_ALLOWED_AMD"/>
          <enum value="2"     name="VK_MEMORY_OVERALLOCATION_BEHAVIOR_DISALLOWED_AMD"/>
      </enums>
+     <enums name="VkFramebufferCreateFlagBits" type="bitmask">
+     </enums>
      <enums name="VkScopeNV" type="enum">
          <enum value="1"     name="VK_SCOPE_DEVICE_NV"/>
          <enum value="2"     name="VK_SCOPE_WORKGROUP_NV"/>


@@ 7533,6 7569,14 @@ <param><type>VkPerformanceParameterTypeINTEL</type> <name>parameter</name></param>
              <param><type>VkPerformanceValueINTEL</type>* <name>pValue</name></param>
          </command>
+         <command successcodes="VK_SUCCESS" errorcodes="VK_ERROR_INITIALIZATION_FAILED">
+             <proto><type>VkResult</type> <name>vkAcquireWaylandDisplayEXT</name></proto>
+             <param><type>VkPhysicalDevice</type> <name>physicalDevice</name></param>
+             <param>struct <type>wl_display</type>* <name>display</name></param>
+             <param>struct <type>zwp_drm_lease_manager_v1</type>* <name>manager</name></param>
+             <param><type>int</type> <name>nConnectors</name></param>
+             <param><type>VkWaylandLeaseConnectorEXT</type>* <name>pConnectors</name></param>
+         </command>
      </commands>
  
      <feature api="vulkan" name="VK_VERSION_1_0" number="1.0" comment="Vulkan core API interface definitions">


@@ 9353,10 9397,18 @@ <enum value="&quot;VK_IMG_extension_108&quot;"              name="VK_IMG_EXTENSION_108_EXTENSION_NAME"/>
              </require>
          </extension>
-         <extension name="VK_IMG_extension_109" number="109" author="IMG" contact="Michael Worcester @michaelworcester" supported="disabled">
+         <extension name="VK_KHR_imageless_framebuffer" requires="VK_KHR_maintenance2,VK_KHR_image_format_list" number="109" author="KHR" contact="Tobias Hector @tobias" type="device" supported="vulkan">
              <require>
-                 <enum value="0"                                             name="VK_IMG_EXTENSION_109_SPEC_VERSION"/>
-                 <enum value="&quot;VK_IMG_extension_109&quot;"              name="VK_IMG_EXTENSION_109_EXTENSION_NAME"/>
+                 <enum value="1"                                             name="VK_KHR_IMAGELESS_FRAMEBUFFER_SPEC_VERSION"/>
+                 <enum value="&quot;VK_KHR_imageless_framebuffer&quot;"      name="VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME"/>
+                 <type name="VkPhysicalDeviceImagelessFramebufferFeaturesKHR"/>
+                 <type name="VkFramebufferAttachmentsCreateInfoKHR"/>
+                 <type name="VkRenderPassAttachmentBeginInfoKHR"/>
+                 <enum offset="0" extends="VkStructureType" name="VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR"/>
+                 <enum offset="1" extends="VkStructureType" name="VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR"/>
+                 <enum offset="2" extends="VkStructureType" name="VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR"/>
+                 <enum offset="3" extends="VkStructureType" name="VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO_KHR"/>
+                 <enum bitpos="0" extends="VkFramebufferCreateFlagBits" name="VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR"/>
              </require>
          </extension>
          <extension name="VK_KHR_create_renderpass2" requires="VK_KHR_multiview,VK_KHR_maintenance2" number="110" contact="Tobias Hector @tobias" type="device" supported="vulkan">


@@ 11136,5 11188,24 @@ <type name="VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT"/>
              </require>
          </extension>
+         <extension name="VK_QCOM_extension_283" number="283" type="device" author="QCOM" contact="Jeff Leger @jackohound" supported="disabled">
+             <require>
+                 <enum value="0"                                             name="VK_QCOM_EXTENSION_283_SPEC_VERSION"/>
+                 <enum value="&quot;VK_QCOM_extension_283&quot;"              name="VK_QCOM_extension_283"/>
+             </require>
+         </extension>
+         <extension name="VK_EXT_extension_284" number="284" type="device" author="EXT" contact="Samuel Pitoiset @hakzsam" supported="disabled">
+             <require>
+                 <enum value="0"                                             name="VK_EXT_EXTENSION_284_SPEC_VERSION"/>
+                 <enum value="&quot;VK_EXT_extension_284&quot;"              name="VK_EXT_extension_284"/>
+             </require>
+         </extension>
+         <extension name="VK_EXT_acquire_wl_display" number="285" type="instance" requires="VK_EXT_direct_mode_display" author="MESA" contact="Drew DeVault @ddevault" platform="wayland" supported="vulkan">
+             <require>
+                 <enum value="1"                                             name="VK_EXT_ACQUIRE_WL_DISPLAY_SPEC_VERSION"/>
+                 <enum value="&quot;VK_EXT_acquire_wl_display&quot;"         name="VK_EXT_ACQUIRE_WL_DISPLAY_EXTENSION_NAME"/>
+                 <command name="vkAcquireWaylandDisplayEXT"/>
+             </require>
+         </extension>
      </extensions>
  </registry>

A src/vulkan/wsi/drm-lease-unstable-v1.xml => src/vulkan/wsi/drm-lease-unstable-v1.xml +238 -0
@@ 0,0 1,238 @@
+ <?xml version="1.0" encoding="UTF-8"?>
+ <protocol name="drm_lease_unstable_v1">
+   <copyright>
+     Copyright © 2018 NXP
+     Copyright © 2019 Status Research &amp; Development GmbH.
+ 
+     Permission is hereby granted, free of charge, to any person obtaining a
+     copy of this software and associated documentation files (the "Software"),
+     to deal in the Software without restriction, including without limitation
+     the rights to use, copy, modify, merge, publish, distribute, sublicense,
+     and/or sell copies of the Software, and to permit persons to whom the
+     Software is furnished to do so, subject to the following conditions:
+ 
+     The above copyright notice and this permission notice (including the next
+     paragraph) shall be included in all copies or substantial portions of the
+     Software.
+ 
+     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+     THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+     DEALINGS IN THE SOFTWARE.
+   </copyright>
+ 
+   <interface name="zwp_drm_lease_manager_v1" version="1">
+     <description summary="lease manager">
+       This protocol is used by Wayland compositors which act as Direct
+       Renderering Manager (DRM) masters to lease DRM resources to Wayland
+       clients. Once leased, the compositor will not use the leased resources
+       until the lease is revoked or the client closes the file descriptor.
+ 
+       The lease manager is used to advertise connectors which are available for
+       leasing, and by the client to negotiate a lease request.
+ 
+       Warning! The protocol described in this file is experimental and
+       backward incompatible changes may be made. Backward compatible changes
+       may be added together with the corresponding interface version bump.
+       Backward incompatible changes are done by bumping the version number in
+       the protocol and interface names and resetting the interface version.
+       Once the protocol is to be declared stable, the 'z' prefix and the
+       version number in the protocol and interface names are removed and the
+       interface version number is reset.
+     </description>
+ 
+     <request name="create_lease_request">
+       <description summary="create a lease request object">
+         Creates a lease request object.
+ 
+         See the documentation for zwp_drm_lease_request_v1 for details.
+       </description>
+       <arg name="id" type="new_id" interface="zwp_drm_lease_request_v1" />
+     </request>
+ 
+     <request name="stop">
+       <description summary="stop sending events">
+         Indicates the client no longer wishes to receive connector events. The
+         compositor may still send connector events until it sends the finish
+         event, however.
+ 
+         The client must not send any requests after this one.
+       </description>
+     </request>
+ 
+     <event name="connector">
+       <description summary="advertise connectors available for leases">
+         The compositor may choose to advertise 0 or more connectors which may be
+         leased to clients, and will use this event to do so. This object may be
+         passed into a lease request to lease that connector. See
+         zwp_drm_lease_request_v1.add_connector for details.
+ 
+         When this global is bound, the compositor will send all connectors
+         available for lease, but may send additional connectors at any time.
+       </description>
+       <arg name="id" type="new_id" interface="zwp_drm_lease_connector_v1" />
+     </event>
+ 
+     <event name="finished">
+       <description summary="the compositor has finished using the manager">
+         This event indicates that the compositor is done sending connector
+         events. The compositor will destroy this object immediately after
+         sending this event, and it will become invalid. The client should
+         release any resources associated with this manager after receiving this
+         event.
+       </description>
+     </event>
+   </interface>
+ 
+   <interface name="zwp_drm_lease_connector_v1" version="1">
+     <description summary="a leasable DRM connector">
+       Represents a DRM connector which is available for lease. These objects are
+       created via zwp_drm_lease_manager_v1.connector, and should be passed into
+       lease requests via zwp_drm_lease_request_v1.add_connector.
+     </description>
+ 
+     <event name="name">
+       <description summary="name">
+         The compositor sends this event once the connector is created to
+         indicate the name of this connector. This will not change for the
+         duration of the Wayland session, but is not guaranteed to be consistent
+         between sessions.
+ 
+         If the compositor also supports zxdg_output_manager_v1 and this
+         connector corresponds to a zxdg_output_v1, this name will match the
+         name of this zxdg_output_v1 object.
+       </description>
+       <arg name="name" type="string" summary="connector name" />
+     </event>
+ 
+     <event name="description">
+       <description summary="description">
+         The compositor sends this event once the connector is created to provide
+         a human-readable description for this connector, which may be presented
+         to the user. This will not change for the duration of the Wayland
+         session, but is not guaranteed to be consistent between sessions.
+ 
+         If the compositor also supports zxdg_output_manager_v1 and this
+         connector corresponds to a zxdg_output_v1, this description will match
+         the description of this zxdg_output_v1 object.
+       </description>
+       <arg name="name" type="string" summary="connector name" />
+     </event>
+ 
+     <event name="edid">
+       <description summary="edid">
+         The compositor sends this event once the connector is created to
+         provide a file descriptor which may be memory-mapped to read the
+         connector's EDID, to assist in selecting the correct connectors
+         for lease.
+       </description>
+       <arg name="edid" type="fd" summary="EDID file descriptor" />
+       <arg name="size" type="uint" summary="EDID size, in bytes"/>
+     </event>
+ 
+     <event name="withdrawn">
+       <description summary="lease offer withdrawn">
+         Sent to indicate that the compositor will no longer honor requests for
+         DRM leases which include this connector. The client may still issue a
+         lease request including this connector, but the compositor will send
+         zwp_drm_lease_v1.finished without issuing a lease fd.
+       </description>
+     </event>
+ 
+     <request name="destroy" type="destructor">
+       <description summary="destroy connector">
+         The client may send this request to indicate that it will not issue a
+         lease request for this connector. Clients are encouraged to send this
+         after receiving the "withdrawn" request so that the server can release
+         the resources associated with this connector offer.
+       </description>
+     </request>
+   </interface>
+ 
+   <interface name="zwp_drm_lease_request_v1" version="1">
+     <description summary="DRM lease request">
+       A client that wishes to lease DRM resources will attach the list of
+       connectors advertised with zwp_drm_lease_manager_v1.connector that they
+       wish to lease, then use zwp_drm_lease_request_v1.submit to submit the
+       request.
+     </description>
+ 
+     <enum name="error">
+       <entry name="no_connectors" value="0"
+         summary="request submitted with zero connectors"/>
+       <entry name="submitted_lease" value="1"
+         summary="attempted to reuse a submitted lease"/>
+     </enum>
+ 
+     <request name="destroy" type="destructor">
+       <description summary="destroys the lease request object">
+         Indicates that the client will no longer use this lease request.
+       </description>
+     </request>
+ 
+     <request name="request_connector">
+        <description summary="request a connector for this lease">
+          Indicates that the client would like to lease the given connector.
+          This is only used as a suggestion, the compositor may choose to
+          include any resources in the lease it issues, or change the set of
+          leased resources at any time.
+        </description>
+        <arg name="connector" type="object"
+          interface="zwp_drm_lease_connector_v1" />
+     </request>
+ 
+     <request name="submit">
+        <description summary="submit the lease request">
+          Submits the lease request and creates a new zwp_drm_lease_v1 object.
+          After calling submit, issuing any other request than destroy is a
+          protocol error. Submitting a lease request with no connectors is a
+          protocol error.
+        </description>
+        <arg name="id" type="new_id" interface="zwp_drm_lease_v1" />
+     </request>
+   </interface>
+ 
+   <interface name="zwp_drm_lease_v1" version="1">
+     <description summary="a DRM lease">
+       A DRM lease object is used to transfer the DRM file descriptor to the
+       client and manage the lifetime of the lease.
+     </description>
+ 
+     <event name="lease_fd">
+       <description summary="shares the DRM file descriptor">
+         This event returns a file descriptor suitable for use with DRM-related
+         ioctls. The client should use drmModeGetLease to enumerate the DRM
+         objects which have been leased to them, which may not be the objects
+         they requested. The lease may have zero DRM objects.
+ 
+         The compositor may also issue and immediately revoke the lease if no
+         connectors are leasable, in which case this event is not sent.
+ 
+         It is a protocol error for the compositor to send this event more than
+         once for a given lease.
+       </description>
+       <arg name="leased_fd" type="fd" summary="leased DRM file descriptor" />
+     </event>
+ 
+     <event name="finished">
+       <description summary="sent when the lease has been revoked">
+         When the compositor revokes the lease, it will issue this event to
+         notify clients of the change. If the client requires a new lease, they
+         should destroy this object and submit a new lease request. The
+         compositor will send no further events for this object after sending
+         the finish event.
+       </description>
+     </event>
+ 
+     <request name="destroy" type="destructor">
+       <description summary="destroys the lease object">
+         The client should send this to indicate that it no longer wishes to use
+         this lease. The compositor should use drmModeRevokeLease on the
+         appropriate file descriptor, if necessary, then release this object.
+       </description>
+     </request>
+   </interface>
+ </protocol>

M src/vulkan/wsi/meson.build => src/vulkan/wsi/meson.build +21 -0
@@ 38,6 38,27 @@ files_vulkan_wsi += files('wsi_common_display.c')
  endif
  
+ if with_wl_lease
+   drm_lease_unstable_v1_protocol_c = custom_target(
+     'drm-lease-unstable-v1-protocol.c',
+     input : 'drm-lease-unstable-v1.xml',
+     output : 'drm-lease-unstable-v1-protocol.c',
+     command : [prog_wl_scanner, wl_scanner_arg, '@INPUT@', '@OUTPUT@'],
+   )
+ 
+   drm_lease_unstable_v1_client_protocol_h = custom_target(
+     'linux-dmabuf-unstable-v1-client-protocol.h',
+     input : 'drm-lease-unstable-v1.xml',
+     output : 'drm-lease-unstable-v1-client-protocol.h',
+     command : [prog_wl_scanner, 'client-header', '@INPUT@', '@OUTPUT@'],
+   )
+ 
+   files_vulkan_wsi += [
+     drm_lease_unstable_v1_protocol_c,
+     drm_lease_unstable_v1_client_protocol_h,
+   ]
+ endif
+ 
  libvulkan_wsi = static_library(
    'vulkan_wsi',
    files_vulkan_wsi,

M src/vulkan/wsi/wsi_common_display.c => src/vulkan/wsi/wsi_common_display.c +94 -0
@@ 37,6 37,9 @@ #include <xcb/randr.h>
  #include <X11/Xlib-xcb.h>
  #endif
+ #ifdef VK_USE_PLATFORM_WAYLAND_KHR
+ #include "drm-lease-unstable-v1-client-protocol.h"
+ #endif
  #include "util/hash_table.h"
  #include "util/list.h"
  


@@ 83,6 86,9 @@ #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
     xcb_randr_output_t           output;
  #endif
+ #ifdef VK_USE_PLATFORM_WAYLAND_KHR
+    struct wlr_drm_lease_v1      *drm_lease;
+ #endif
  } wsi_display_connector;
  
  struct wsi_display {


@@ 2530,3 2536,91 @@ return VK_SUCCESS;
  }
  
+ #ifdef VK_USE_PLATFORM_WAYLAND_KHR
+ 
+ static void drm_lease_handle_lease_fd(
+       void *data,
+       struct zwp_drm_lease_v1 *zwp_drm_lease_v1,
+       int32_t leased_fd)
+ {
+    struct wsi_display *wsi = data;
+    wsi->fd = leased_fd;
+ }
+ 
+ static void drm_lease_handle_finished(
+       void *data,
+       struct zwp_drm_lease_v1 *zwp_drm_lease_v1)
+ {
+    struct wsi_display *wsi = data;
+    if (wsi->fd > 0) {
+       close(wsi->fd);
+       wsi->fd = -1;
+    }
+ }
+ 
+ static const struct zwp_drm_lease_v1_listener drm_lease_listener = {
+    drm_lease_handle_lease_fd,
+    drm_lease_handle_finished,
+ };
+ 
+ /* VK_EXT_acquire_wl_display */
+ VkResult
+ wsi_acquire_wl_display(VkPhysicalDevice physical_device,
+                        struct wsi_device *wsi_device,
+                        struct wl_display *display,
+                        struct zwp_drm_lease_manager_v1 *manager,
+                        int nConnectors,
+                        VkWaylandLeaseConnectorEXT *connectors)
+ {
+    struct wsi_display *wsi =
+       (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLATFORM_DISPLAY];
+ 
+    /* XXX no support for mulitple leases yet */
+    if (wsi->fd >= 0)
+       return VK_ERROR_INITIALIZATION_FAILED;
+ 
+    /* XXX no support for mulitple connectors yet */
+    /* The solution will eventually involve adding a listener to each
+     * connector, round tripping, and matching EDIDs once the lease is
+     * granted. */
+    if (nConnectors > 1)
+       return VK_ERROR_INITIALIZATION_FAILED;
+ 
+    struct zwp_drm_lease_request_v1 *lease_request =
+       zwp_drm_lease_manager_v1_create_lease_request(manager);
+    for (int i = 0; i < nConnectors; ++i) {
+       zwp_drm_lease_request_v1_request_connector(lease_request,
+                                                  connectors[i].pConnectorIn);
+    }
+ 
+    struct zwp_drm_lease_v1 *drm_lease =
+       zwp_drm_lease_request_v1_submit(lease_request);
+    zwp_drm_lease_request_v1_destroy(lease_request);
+    zwp_drm_lease_v1_add_listener(drm_lease, &drm_lease_listener, wsi);
+    wl_display_roundtrip(display);
+ 
+    if (wsi->fd < 0)
+       return VK_ERROR_INITIALIZATION_FAILED;
+ 
+    int nconn = 0;
+    drmModeResPtr res = drmModeGetResources(wsi->fd);
+    drmModeObjectListPtr lease = drmModeGetLease(wsi->fd);
+    for (uint32_t i = 0; i < res->count_connectors; ++i) {
+       for (uint32_t j = 0; j < lease->count; ++j) {
+          if (res->connectors[i] != lease->objects[j]) {
+             continue;
+          }
+          struct wsi_display_connector *connector =
+             wsi_display_get_connector(wsi_device, res->connectors[i]);
+          /* TODO: Match EDID with requested connector */
+          connectors[nconn].displayOut =
+             wsi_display_connector_to_handle(connector);
+          ++nconn;
+       }
+    }
+    drmModeFreeResources(res);
+ 
+    return VK_SUCCESS;
+ }
+ 
+ #endif /* VK_USE_PLATFORM_WAYLAND_KHR */

M src/vulkan/wsi/wsi_common_display.h => src/vulkan/wsi/wsi_common_display.h +13 -0
@@ 160,4 160,17 @@ VkSurfaceCounterFlagBitsEXT   flag_bits,
                            uint64_t                      *value);
  
+ #ifdef VK_USE_PLATFORM_WAYLAND_KHR
+ 
+ /* VK_EXT_acquire_wl_display */
+ VkResult
+ wsi_acquire_wl_display(VkPhysicalDevice                 physical_device,
+                        struct wsi_device                *wsi_device,
+                        struct wl_display                *display,
+                        struct zwp_drm_lease_manager_v1  *manager,
+                        int                              nConnectors,
+                        VkWaylandLeaseConnectorEXT       *connectors);
+ 
+ #endif /* VK_USE_PLATFORM_WAYLAND_KHR */
+ 
  #endif