diff options
author | Jason Ekstrand <[email protected]> | 2020-01-10 13:16:25 -0600 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-01-14 19:27:13 +0000 |
commit | 7c16a1ae4e629ccbae3979ec9be105e6b44e0acf (patch) | |
tree | bf1b44b0e0180e99545f48f9d060bb1aeb1e949a /src/vulkan | |
parent | edf6a40cb2a09d58f9244abf0a1432a836a350ce (diff) |
vulkan/wsi: Add a driconf option to force WSI to advertise BGRA8_UNORM first
The Aztec Ruins benchmark just grabs the first format in the list and
SRGB causes it to render washed out. With this workaround, it renders
the same as OpenGL.
Reviewed-by: Lionel Landwerlin <[email protected]>
Reviewed-by: Samuel Pitoiset <[email protected]>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3350>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3350>
Diffstat (limited to 'src/vulkan')
-rw-r--r-- | src/vulkan/wsi/wsi_common.c | 5 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common.h | 1 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_display.c | 31 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_wayland.c | 15 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_x11.c | 30 |
5 files changed, 74 insertions, 8 deletions
diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c index e45810d9c5d..1fb2bf7df3e 100644 --- a/src/vulkan/wsi/wsi_common.c +++ b/src/vulkan/wsi/wsi_common.c @@ -135,6 +135,11 @@ wsi_device_init(struct wsi_device *wsi, if (driCheckOption(dri_options, "adaptive_sync", DRI_BOOL)) wsi->enable_adaptive_sync = driQueryOptionb(dri_options, "adaptive_sync"); + + if (driCheckOption(dri_options, "vk_wsi_force_bgra8_unorm_first", DRI_BOOL)) { + wsi->force_bgra8_unorm_first = + driQueryOptionb(dri_options, "vk_wsi_force_bgra8_unorm_first"); + } } return VK_SUCCESS; diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h index 704c1abd809..3e3f79b1a4a 100644 --- a/src/vulkan/wsi/wsi_common.h +++ b/src/vulkan/wsi/wsi_common.h @@ -112,6 +112,7 @@ struct wsi_device { bool supports_modifiers; uint32_t maxImageDimension2D; VkPresentModeKHR override_present_mode; + bool force_bgra8_unorm_first; /* Whether to enable adaptive sync for a swapchain if implemented and * available. Not all window systems might support this. */ diff --git a/src/vulkan/wsi/wsi_common_display.c b/src/vulkan/wsi/wsi_common_display.c index 66e191906fc..04c77162df4 100644 --- a/src/vulkan/wsi/wsi_common_display.c +++ b/src/vulkan/wsi/wsi_common_display.c @@ -896,6 +896,23 @@ static const struct { { .format = VK_FORMAT_B8G8R8A8_UNORM, .drm_format = DRM_FORMAT_XRGB8888 }, }; +static void +get_sorted_vk_formats(struct wsi_device *wsi_device, VkFormat *sorted_formats) +{ + for (unsigned i = 0; i < ARRAY_SIZE(available_surface_formats); i++) + sorted_formats[i] = available_surface_formats[i].format; + + if (wsi_device->force_bgra8_unorm_first) { + for (unsigned i = 0; i < ARRAY_SIZE(available_surface_formats); i++) { + if (sorted_formats[i] == VK_FORMAT_B8G8R8A8_UNORM) { + sorted_formats[i] = sorted_formats[0]; + sorted_formats[0] = VK_FORMAT_B8G8R8A8_UNORM; + break; + } + } + } +} + static VkResult wsi_display_surface_get_formats(VkIcdSurfaceBase *icd_surface, struct wsi_device *wsi_device, @@ -904,9 +921,12 @@ wsi_display_surface_get_formats(VkIcdSurfaceBase *icd_surface, { VK_OUTARRAY_MAKE(out, surface_formats, surface_format_count); - for (unsigned i = 0; i < ARRAY_SIZE(available_surface_formats); i++) { + VkFormat sorted_formats[ARRAY_SIZE(available_surface_formats)]; + get_sorted_vk_formats(wsi_device, sorted_formats); + + for (unsigned i = 0; i < ARRAY_SIZE(sorted_formats); i++) { vk_outarray_append(&out, f) { - f->format = available_surface_formats[i].format; + f->format = sorted_formats[i]; f->colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; } } @@ -923,10 +943,13 @@ wsi_display_surface_get_formats2(VkIcdSurfaceBase *surface, { VK_OUTARRAY_MAKE(out, surface_formats, surface_format_count); - for (unsigned i = 0; i < ARRAY_SIZE(available_surface_formats); i++) { + VkFormat sorted_formats[ARRAY_SIZE(available_surface_formats)]; + get_sorted_vk_formats(wsi_device, sorted_formats); + + for (unsigned i = 0; i < ARRAY_SIZE(sorted_formats); i++) { vk_outarray_append(&out, f) { assert(f->sType == VK_STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR); - f->surfaceFormat.format = available_surface_formats[i].format; + f->surfaceFormat.format = sorted_formats[i]; f->surfaceFormat.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; } } diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index 438c2f50da3..dcea92a858a 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -421,6 +421,21 @@ wsi_wl_display_init(struct wsi_wayland *wsi_wl, if (display->drm.wl_drm || display->dmabuf.wl_dmabuf) wl_display_roundtrip_queue(display->wl_display, display->queue); + if (wsi_wl->wsi->force_bgra8_unorm_first) { + /* Find BGRA8_UNORM in the list and swap it to the first position if we + * can find it. Some apps get confused if SRGB is first in the list. + */ + VkFormat *first_fmt = u_vector_head(display->formats); + VkFormat *iter_fmt; + u_vector_foreach(iter_fmt, display->formats) { + if (*iter_fmt == VK_FORMAT_B8G8R8A8_UNORM) { + *iter_fmt = *first_fmt; + *first_fmt = VK_FORMAT_B8G8R8A8_UNORM; + break; + } + } + } + /* We need prime support for wl_drm */ if (display->drm.wl_drm && (display->drm.capabilities & WL_DRM_CAPABILITY_PRIME)) { diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c index 491bd8a3702..95106af5b6e 100644 --- a/src/vulkan/wsi/wsi_common_x11.c +++ b/src/vulkan/wsi/wsi_common_x11.c @@ -569,6 +569,22 @@ x11_surface_get_capabilities2(VkIcdSurfaceBase *icd_surface, return result; } +static void +get_sorted_vk_formats(struct wsi_device *wsi_device, VkFormat *sorted_formats) +{ + memcpy(sorted_formats, formats, sizeof(formats)); + + if (wsi_device->force_bgra8_unorm_first) { + for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) { + if (sorted_formats[i] == VK_FORMAT_B8G8R8A8_UNORM) { + sorted_formats[i] = sorted_formats[0]; + sorted_formats[0] = VK_FORMAT_B8G8R8A8_UNORM; + break; + } + } + } +} + static VkResult x11_surface_get_formats(VkIcdSurfaceBase *surface, struct wsi_device *wsi_device, @@ -577,9 +593,12 @@ x11_surface_get_formats(VkIcdSurfaceBase *surface, { VK_OUTARRAY_MAKE(out, pSurfaceFormats, pSurfaceFormatCount); - for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) { + VkFormat sorted_formats[ARRAY_SIZE(formats)]; + get_sorted_vk_formats(wsi_device, sorted_formats); + + for (unsigned i = 0; i < ARRAY_SIZE(sorted_formats); i++) { vk_outarray_append(&out, f) { - f->format = formats[i]; + f->format = sorted_formats[i]; f->colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; } } @@ -596,10 +615,13 @@ x11_surface_get_formats2(VkIcdSurfaceBase *surface, { VK_OUTARRAY_MAKE(out, pSurfaceFormats, pSurfaceFormatCount); - for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) { + VkFormat sorted_formats[ARRAY_SIZE(formats)]; + get_sorted_vk_formats(wsi_device, sorted_formats); + + for (unsigned i = 0; i < ARRAY_SIZE(sorted_formats); i++) { vk_outarray_append(&out, f) { assert(f->sType == VK_STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR); - f->surfaceFormat.format = formats[i]; + f->surfaceFormat.format = sorted_formats[i]; f->surfaceFormat.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; } } |