[Mesa-dev] [PATCH 1/2] wsi: add an option that allows to force enable vsync at device creation

Samuel Pitoiset samuel.pitoiset at gmail.com
Mon Apr 8 20:42:13 UTC 2019


When the WSI device wants to enable vsync, it just switches
to the FIFO presentation mode.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/amd/vulkan/radv_wsi.c           | 2 +-
 src/freedreno/vulkan/tu_wsi.c       | 2 +-
 src/intel/vulkan/anv_wsi.c          | 2 +-
 src/vulkan/wsi/wsi_common.c         | 4 +++-
 src/vulkan/wsi/wsi_common.h         | 4 +++-
 src/vulkan/wsi/wsi_common_display.c | 3 +++
 src/vulkan/wsi/wsi_common_wayland.c | 3 +++
 src/vulkan/wsi/wsi_common_x11.c     | 3 +++
 8 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c
index 346fb43d675..2fd07447668 100644
--- a/src/amd/vulkan/radv_wsi.c
+++ b/src/amd/vulkan/radv_wsi.c
@@ -42,7 +42,7 @@ radv_init_wsi(struct radv_physical_device *physical_device)
 			       radv_physical_device_to_handle(physical_device),
 			       radv_wsi_proc_addr,
 			       &physical_device->instance->alloc,
-			       physical_device->master_fd);
+			       physical_device->master_fd, false);
 }
 
 void
diff --git a/src/freedreno/vulkan/tu_wsi.c b/src/freedreno/vulkan/tu_wsi.c
index ce06a05d5d5..8ea12010a19 100644
--- a/src/freedreno/vulkan/tu_wsi.c
+++ b/src/freedreno/vulkan/tu_wsi.c
@@ -40,7 +40,7 @@ tu_wsi_init(struct tu_physical_device *physical_device)
    return wsi_device_init(&physical_device->wsi_device,
                           tu_physical_device_to_handle(physical_device),
                           tu_wsi_proc_addr, &physical_device->instance->alloc,
-                          physical_device->master_fd);
+                          physical_device->master_fd, false);
 }
 
 void
diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c
index 024bc1c245d..d24f076dce5 100644
--- a/src/intel/vulkan/anv_wsi.c
+++ b/src/intel/vulkan/anv_wsi.c
@@ -49,7 +49,7 @@ anv_init_wsi(struct anv_physical_device *physical_device)
                             anv_physical_device_to_handle(physical_device),
                             anv_wsi_proc_addr,
                             &physical_device->instance->alloc,
-                            physical_device->master_fd);
+                            physical_device->master_fd, false);
    if (result != VK_SUCCESS)
       return result;
 
diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c
index 3cba0a4b06e..6c92f3282e1 100644
--- a/src/vulkan/wsi/wsi_common.c
+++ b/src/vulkan/wsi/wsi_common.c
@@ -35,7 +35,8 @@ wsi_device_init(struct wsi_device *wsi,
                 VkPhysicalDevice pdevice,
                 WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
                 const VkAllocationCallbacks *alloc,
-                int display_fd)
+                int display_fd,
+                bool forces_vsync)
 {
    VkResult result;
 
@@ -60,6 +61,7 @@ wsi_device_init(struct wsi_device *wsi,
    GetPhysicalDeviceProperties2(pdevice, &pdp2);
 
    wsi->maxImageDimension2D = pdp2.properties.limits.maxImageDimension2D;
+   wsi->forces_vsync = forces_vsync;
 
    GetPhysicalDeviceMemoryProperties(pdevice, &wsi->memory_props);
    GetPhysicalDeviceQueueFamilyProperties(pdevice, &wsi->queue_family_count, NULL);
diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h
index e693e2be425..3f4c8d44936 100644
--- a/src/vulkan/wsi/wsi_common.h
+++ b/src/vulkan/wsi/wsi_common.h
@@ -100,6 +100,7 @@ struct wsi_device {
    VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info;
 
    bool supports_modifiers;
+   bool forces_vsync;
    uint32_t maxImageDimension2D;
 
    uint64_t (*image_get_modifier)(VkImage image);
@@ -143,7 +144,8 @@ wsi_device_init(struct wsi_device *wsi,
                 VkPhysicalDevice pdevice,
                 WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
                 const VkAllocationCallbacks *alloc,
-                int display_fd);
+                int display_fd,
+                bool forces_vsync);
 
 void
 wsi_device_finish(struct wsi_device *wsi,
diff --git a/src/vulkan/wsi/wsi_common_display.c b/src/vulkan/wsi/wsi_common_display.c
index 09c18315623..d0f3d519e29 100644
--- a/src/vulkan/wsi/wsi_common_display.c
+++ b/src/vulkan/wsi/wsi_common_display.c
@@ -1765,6 +1765,9 @@ wsi_display_surface_create_swapchain(
 
    chain->surface = (VkIcdSurfaceDisplay *) icd_surface;
 
+   if (wsi_device->forces_vsync)
+      chain->base.present_mode = VK_PRESENT_MODE_FIFO_KHR;
+
    for (uint32_t image = 0; image < chain->base.image_count; image++) {
       result = wsi_display_image_init(device, &chain->base,
                                       create_info, allocator,
diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c
index a312a99d412..3a5b0632c7c 100644
--- a/src/vulkan/wsi/wsi_common_wayland.c
+++ b/src/vulkan/wsi/wsi_common_wayland.c
@@ -981,6 +981,9 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
    chain->vk_format = pCreateInfo->imageFormat;
    chain->drm_format = wl_drm_format_for_vk_format(chain->vk_format, alpha);
 
+   if (wsi_device->forces_vsync)
+      chain->base.present_mode = VK_PRESENT_MODE_FIFO_KHR;
+
    if (pCreateInfo->oldSwapchain) {
       /* If we have an oldSwapchain parameter, copy the display struct over
        * from the old one so we don't have to fully re-initialize it.
diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c
index c87b9312636..659245a2b70 100644
--- a/src/vulkan/wsi/wsi_common_x11.c
+++ b/src/vulkan/wsi/wsi_common_x11.c
@@ -1373,6 +1373,9 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
    chain->status = VK_SUCCESS;
    chain->has_dri3_modifiers = wsi_conn->has_dri3_modifiers;
 
+   if (wsi_device->forces_vsync)
+      chain->base.present_mode = VK_PRESENT_MODE_FIFO_KHR;
+
    /* If we are reallocating from an old swapchain, then we inherit its
     * last completion mode, to ensure we don't get into reallocation
     * cycles. If we are starting anew, we set 'COPY', as that is the only
-- 
2.21.0



More information about the mesa-dev mailing list