mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-20 22:30:12 +01:00
wsi: allow to override the present mode with MESA_VK_WSI_PRESENT_MODE
This is common to all Vulkan drivers and all WSI. Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
This commit is contained in:
parent
09b4049be3
commit
a182adfd83
6 changed files with 78 additions and 3 deletions
|
|
@ -29,6 +29,8 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <xf86drm.h>
|
#include <xf86drm.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
VkResult
|
VkResult
|
||||||
wsi_device_init(struct wsi_device *wsi,
|
wsi_device_init(struct wsi_device *wsi,
|
||||||
|
|
@ -37,6 +39,7 @@ wsi_device_init(struct wsi_device *wsi,
|
||||||
const VkAllocationCallbacks *alloc,
|
const VkAllocationCallbacks *alloc,
|
||||||
int display_fd)
|
int display_fd)
|
||||||
{
|
{
|
||||||
|
const char *present_mode;
|
||||||
VkResult result;
|
VkResult result;
|
||||||
|
|
||||||
memset(wsi, 0, sizeof(*wsi));
|
memset(wsi, 0, sizeof(*wsi));
|
||||||
|
|
@ -60,6 +63,7 @@ wsi_device_init(struct wsi_device *wsi,
|
||||||
GetPhysicalDeviceProperties2(pdevice, &pdp2);
|
GetPhysicalDeviceProperties2(pdevice, &pdp2);
|
||||||
|
|
||||||
wsi->maxImageDimension2D = pdp2.properties.limits.maxImageDimension2D;
|
wsi->maxImageDimension2D = pdp2.properties.limits.maxImageDimension2D;
|
||||||
|
wsi->override_present_mode = VK_PRESENT_MODE_MAX_ENUM_KHR;
|
||||||
|
|
||||||
GetPhysicalDeviceMemoryProperties(pdevice, &wsi->memory_props);
|
GetPhysicalDeviceMemoryProperties(pdevice, &wsi->memory_props);
|
||||||
GetPhysicalDeviceQueueFamilyProperties(pdevice, &wsi->queue_family_count, NULL);
|
GetPhysicalDeviceQueueFamilyProperties(pdevice, &wsi->queue_family_count, NULL);
|
||||||
|
|
@ -112,6 +116,19 @@ wsi_device_init(struct wsi_device *wsi,
|
||||||
goto fail;
|
goto fail;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
present_mode = getenv("MESA_VK_WSI_PRESENT_MODE");
|
||||||
|
if (present_mode) {
|
||||||
|
if (!strcmp(present_mode, "fifo")) {
|
||||||
|
wsi->override_present_mode = VK_PRESENT_MODE_FIFO_KHR;
|
||||||
|
} else if (!strcmp(present_mode, "mailbox")) {
|
||||||
|
wsi->override_present_mode = VK_PRESENT_MODE_MAILBOX_KHR;
|
||||||
|
} else if (!strcmp(present_mode, "immediate")) {
|
||||||
|
wsi->override_present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Invalid MESA_VK_WSI_PRESENT_MODE value!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|
@ -202,6 +219,59 @@ fail:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
wsi_swapchain_is_present_mode_supported(struct wsi_device *wsi,
|
||||||
|
const VkSwapchainCreateInfoKHR *pCreateInfo,
|
||||||
|
VkPresentModeKHR mode)
|
||||||
|
{
|
||||||
|
ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, pCreateInfo->surface);
|
||||||
|
struct wsi_interface *iface = wsi->wsi[surface->platform];
|
||||||
|
VkPresentModeKHR *present_modes;
|
||||||
|
uint32_t present_mode_count;
|
||||||
|
bool supported = false;
|
||||||
|
VkResult result;
|
||||||
|
|
||||||
|
result = iface->get_present_modes(surface, &present_mode_count, NULL);
|
||||||
|
if (result != VK_SUCCESS)
|
||||||
|
return supported;
|
||||||
|
|
||||||
|
present_modes = malloc(present_mode_count * sizeof(*present_modes));
|
||||||
|
if (!present_modes)
|
||||||
|
return supported;
|
||||||
|
|
||||||
|
result = iface->get_present_modes(surface, &present_mode_count,
|
||||||
|
present_modes);
|
||||||
|
if (result != VK_SUCCESS)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < present_mode_count; i++) {
|
||||||
|
if (present_modes[i] == mode) {
|
||||||
|
supported = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fail:
|
||||||
|
free(present_modes);
|
||||||
|
return supported;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum VkPresentModeKHR
|
||||||
|
wsi_swapchain_get_present_mode(struct wsi_device *wsi,
|
||||||
|
const VkSwapchainCreateInfoKHR *pCreateInfo)
|
||||||
|
{
|
||||||
|
if (wsi->override_present_mode == VK_PRESENT_MODE_MAX_ENUM_KHR)
|
||||||
|
return pCreateInfo->presentMode;
|
||||||
|
|
||||||
|
if (!wsi_swapchain_is_present_mode_supported(wsi, pCreateInfo,
|
||||||
|
wsi->override_present_mode)) {
|
||||||
|
fprintf(stderr, "Unsupported MESA_VK_WSI_PRESENT_MODE value!\n");
|
||||||
|
return pCreateInfo->presentMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wsi->override_present_mode;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wsi_swapchain_finish(struct wsi_swapchain *chain)
|
wsi_swapchain_finish(struct wsi_swapchain *chain)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,7 @@ struct wsi_device {
|
||||||
|
|
||||||
bool supports_modifiers;
|
bool supports_modifiers;
|
||||||
uint32_t maxImageDimension2D;
|
uint32_t maxImageDimension2D;
|
||||||
|
VkPresentModeKHR override_present_mode;
|
||||||
|
|
||||||
uint64_t (*image_get_modifier)(VkImage image);
|
uint64_t (*image_get_modifier)(VkImage image);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1757,7 +1757,7 @@ wsi_display_surface_create_swapchain(
|
||||||
chain->base.get_wsi_image = wsi_display_get_wsi_image;
|
chain->base.get_wsi_image = wsi_display_get_wsi_image;
|
||||||
chain->base.acquire_next_image = wsi_display_acquire_next_image;
|
chain->base.acquire_next_image = wsi_display_acquire_next_image;
|
||||||
chain->base.queue_present = wsi_display_queue_present;
|
chain->base.queue_present = wsi_display_queue_present;
|
||||||
chain->base.present_mode = create_info->presentMode;
|
chain->base.present_mode = wsi_swapchain_get_present_mode(wsi_device, create_info);
|
||||||
chain->base.image_count = num_images;
|
chain->base.image_count = num_images;
|
||||||
|
|
||||||
chain->wsi = wsi;
|
chain->wsi = wsi;
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,10 @@ wsi_swapchain_init(const struct wsi_device *wsi,
|
||||||
const VkSwapchainCreateInfoKHR *pCreateInfo,
|
const VkSwapchainCreateInfoKHR *pCreateInfo,
|
||||||
const VkAllocationCallbacks *pAllocator);
|
const VkAllocationCallbacks *pAllocator);
|
||||||
|
|
||||||
|
enum VkPresentModeKHR
|
||||||
|
wsi_swapchain_get_present_mode(struct wsi_device *wsi,
|
||||||
|
const VkSwapchainCreateInfoKHR *pCreateInfo);
|
||||||
|
|
||||||
void wsi_swapchain_finish(struct wsi_swapchain *chain);
|
void wsi_swapchain_finish(struct wsi_swapchain *chain);
|
||||||
|
|
||||||
VkResult
|
VkResult
|
||||||
|
|
|
||||||
|
|
@ -1009,7 +1009,7 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
|
||||||
chain->base.get_wsi_image = wsi_wl_swapchain_get_wsi_image;
|
chain->base.get_wsi_image = wsi_wl_swapchain_get_wsi_image;
|
||||||
chain->base.acquire_next_image = wsi_wl_swapchain_acquire_next_image;
|
chain->base.acquire_next_image = wsi_wl_swapchain_acquire_next_image;
|
||||||
chain->base.queue_present = wsi_wl_swapchain_queue_present;
|
chain->base.queue_present = wsi_wl_swapchain_queue_present;
|
||||||
chain->base.present_mode = pCreateInfo->presentMode;
|
chain->base.present_mode = wsi_swapchain_get_present_mode(wsi_device, pCreateInfo);
|
||||||
chain->base.image_count = num_images;
|
chain->base.image_count = num_images;
|
||||||
chain->extent = pCreateInfo->imageExtent;
|
chain->extent = pCreateInfo->imageExtent;
|
||||||
chain->vk_format = pCreateInfo->imageFormat;
|
chain->vk_format = pCreateInfo->imageFormat;
|
||||||
|
|
|
||||||
|
|
@ -1361,7 +1361,7 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
|
||||||
chain->base.get_wsi_image = x11_get_wsi_image;
|
chain->base.get_wsi_image = x11_get_wsi_image;
|
||||||
chain->base.acquire_next_image = x11_acquire_next_image;
|
chain->base.acquire_next_image = x11_acquire_next_image;
|
||||||
chain->base.queue_present = x11_queue_present;
|
chain->base.queue_present = x11_queue_present;
|
||||||
chain->base.present_mode = pCreateInfo->presentMode;
|
chain->base.present_mode = wsi_swapchain_get_present_mode(wsi_device, pCreateInfo);
|
||||||
chain->base.image_count = num_images;
|
chain->base.image_count = num_images;
|
||||||
chain->conn = conn;
|
chain->conn = conn;
|
||||||
chain->window = window;
|
chain->window = window;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue