wsi/x11: Make get_sorted_vk_formats handle varying channel widths
Depths 24 and 30 happen to have uniform bpc but 16 does not. Pull the real channel width out of the format description instead. This is still a bit ignorant of channel order though. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20673>
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
#include "util/xmlconfig.h"
|
||||
#include "util/timespec.h"
|
||||
|
||||
#include "vk_format.h"
|
||||
#include "vk_instance.h"
|
||||
#include "vk_physical_device.h"
|
||||
#include "vk_util.h"
|
||||
@@ -415,15 +416,10 @@ wsi_x11_get_connection(struct wsi_device *wsi_dev,
|
||||
return entry->data;
|
||||
}
|
||||
|
||||
struct surface_format {
|
||||
VkFormat format;
|
||||
unsigned bits_per_rgb;
|
||||
};
|
||||
|
||||
static const struct surface_format formats[] = {
|
||||
{ VK_FORMAT_B8G8R8A8_SRGB, 8 },
|
||||
{ VK_FORMAT_B8G8R8A8_UNORM, 8 },
|
||||
{ VK_FORMAT_A2R10G10B10_UNORM_PACK32, 10 },
|
||||
static const VkFormat formats[] = {
|
||||
VK_FORMAT_B8G8R8A8_SRGB,
|
||||
VK_FORMAT_B8G8R8A8_UNORM,
|
||||
VK_FORMAT_A2R10G10B10_UNORM_PACK32,
|
||||
};
|
||||
|
||||
static const VkPresentModeKHR present_modes[] = {
|
||||
@@ -749,6 +745,12 @@ x11_surface_get_capabilities2(VkIcdSurfaceBase *icd_surface,
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
format_get_component_bits(VkFormat format, int comp)
|
||||
{
|
||||
return vk_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, comp);
|
||||
}
|
||||
|
||||
static bool
|
||||
get_sorted_vk_formats(VkIcdSurfaceBase *surface, struct wsi_device *wsi_device,
|
||||
VkFormat *sorted_formats, unsigned *count)
|
||||
@@ -756,15 +758,16 @@ get_sorted_vk_formats(VkIcdSurfaceBase *surface, struct wsi_device *wsi_device,
|
||||
xcb_connection_t *conn = x11_surface_get_connection(surface);
|
||||
xcb_window_t window = x11_surface_get_window(surface);
|
||||
xcb_visualtype_t *visual = get_visualtype_for_window(conn, window, NULL);
|
||||
|
||||
if (!visual)
|
||||
return false;
|
||||
|
||||
*count = 0;
|
||||
for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) {
|
||||
if (formats[i].bits_per_rgb == util_bitcount(visual->red_mask) &&
|
||||
formats[i].bits_per_rgb == util_bitcount(visual->green_mask) &&
|
||||
formats[i].bits_per_rgb == util_bitcount(visual->blue_mask))
|
||||
sorted_formats[(*count)++] = formats[i].format;
|
||||
if (format_get_component_bits(formats[i], 0) == util_bitcount(visual->red_mask) &&
|
||||
format_get_component_bits(formats[i], 1) == util_bitcount(visual->green_mask) &&
|
||||
format_get_component_bits(formats[i], 2) == util_bitcount(visual->blue_mask))
|
||||
sorted_formats[(*count)++] = formats[i];
|
||||
}
|
||||
|
||||
if (wsi_device->force_bgra8_unorm_first) {
|
||||
|
||||
Reference in New Issue
Block a user