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 <lionel.g.landwerlin@intel.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3350>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3350>
This commit is contained in:
Jason Ekstrand
2020-01-10 13:16:25 -06:00
committed by Marge Bot
parent edf6a40cb2
commit 7c16a1ae4e
9 changed files with 85 additions and 8 deletions
+5
View File
@@ -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;
+1
View File
@@ -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. */
+27 -4
View File
@@ -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;
}
}
+15
View File
@@ -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)) {
+26 -4
View File
@@ -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;
}
}