[Mesa-dev] [PATCH 2/2] vulkan/wsi/wayland: Use the format utilities to find compatible VkFormats
alexandros.frantzis at collabora.com
alexandros.frantzis at collabora.com
Fri Jun 23 15:50:51 UTC 2017
From: Alexandros Frantzis <alexandros.frantzis at collabora.com>
Express the WL_DRM_FORMATs in terms of vk_format_util_spec and use the
format utilities to find compatible Vulkan formats.
---
src/vulkan/wsi/wsi_common_wayland.c | 178 ++++++++++++++++++------------------
1 file changed, 91 insertions(+), 87 deletions(-)
diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c
index dd283a1211..a42d056b17 100644
--- a/src/vulkan/wsi/wsi_common_wayland.c
+++ b/src/vulkan/wsi/wsi_common_wayland.c
@@ -31,6 +31,7 @@
#include <string.h>
#include <pthread.h>
+#include "vk_format_util.h"
#include "vk_util.h"
#include "wsi_common_wayland.h"
#include "wayland-drm-client-protocol.h"
@@ -101,105 +102,108 @@ drm_handle_device(void *data, struct wl_drm *drm, const char *name)
fprintf(stderr, "wl_drm.device(%s)\n", name);
}
+struct drm_format_spec {
+ uint32_t format;
+ struct vk_format_util_spec vspec;
+ bool has_alpha;
+};
+
+#define WF(FMT, BPP, R, G, B, A, S, HA) \
+ {WL_DRM_FORMAT_##FMT, {BPP, R, G, B, A, VK_FORMAT_UTIL_ENDIANNESS_LITTLE, VK_FORMAT_UTIL_##S}, HA}
+
+static const struct drm_format_spec drm_format_specs[] = {
+ WF(C8, 8, 0x000000ff, 0x00000000, 0x00000000, 0x00000000, SWAPPABLE, false),
+ WF(RGB332, 8, 0x000000e0, 0x0000001c, 0x00000003, 0x00000000, NON_SWAPPABLE, false),
+ WF(BGR233, 8, 0x00000007, 0x00000038, 0x000000c0, 0x00000000, NON_SWAPPABLE, false),
+ WF(XRGB4444, 16, 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000, NON_SWAPPABLE, false),
+ WF(XBGR4444, 16, 0x0000000f, 0x000000f0, 0x00000f00, 0x0000f000, NON_SWAPPABLE, false),
+ WF(RGBX4444, 16, 0x0000f000, 0x00000f00, 0x000000f0, 0x0000000f, NON_SWAPPABLE, false),
+ WF(BGRX4444, 16, 0x000000f0, 0x00000f00, 0x0000f000, 0x0000000f, NON_SWAPPABLE, false),
+ WF(ARGB4444, 16, 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000, NON_SWAPPABLE, true),
+ WF(ABGR4444, 16, 0x0000000f, 0x000000f0, 0x00000f00, 0x0000f000, NON_SWAPPABLE, true),
+ WF(RGBA4444, 16, 0x0000f000, 0x00000f00, 0x000000f0, 0x0000000f, NON_SWAPPABLE, true),
+ WF(BGRA4444, 16, 0x000000f0, 0x00000f00, 0x0000f000, 0x0000000f, NON_SWAPPABLE, true),
+ WF(XRGB1555, 16, 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000, NON_SWAPPABLE, false),
+ WF(XBGR1555, 16, 0x0000001f, 0x000003e0, 0x00007c00, 0x00008000, NON_SWAPPABLE, false),
+ WF(RGBX5551, 16, 0x0000f800, 0x000007c0, 0x0000003e, 0x00000001, NON_SWAPPABLE, false),
+ WF(BGRX5551, 16, 0x0000003e, 0x000007c0, 0x0000f800, 0x00000001, NON_SWAPPABLE, false),
+ WF(ARGB1555, 16, 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000, NON_SWAPPABLE, true),
+ WF(ABGR1555, 16, 0x0000001f, 0x000003e0, 0x00007c00, 0x00008000, NON_SWAPPABLE, true),
+ WF(RGBA5551, 16, 0x0000f800, 0x000007c0, 0x0000003e, 0x00000001, NON_SWAPPABLE, true),
+ WF(BGRA5551, 16, 0x0000003e, 0x000007c0, 0x0000f800, 0x00000001, NON_SWAPPABLE, true),
+ WF(RGB565, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000, NON_SWAPPABLE, false),
+ WF(BGR565, 16, 0x0000001f, 0x000007e0, 0x0000f800, 0x00000000, NON_SWAPPABLE, false),
+ WF(RGB888, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000, SWAPPABLE, false),
+ WF(BGR888, 24, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000, SWAPPABLE, false),
+ WF(XRGB8888, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, SWAPPABLE, false),
+ WF(XBGR8888, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, SWAPPABLE, false),
+ WF(RGBX8888, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, SWAPPABLE, false),
+ WF(BGRX8888, 32, 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff, SWAPPABLE, false),
+ WF(ARGB8888, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, SWAPPABLE, true),
+ WF(ABGR8888, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, SWAPPABLE, true),
+ WF(RGBA8888, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, SWAPPABLE, true),
+ WF(BGRA8888, 32, 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff, SWAPPABLE, true),
+ WF(XRGB2101010, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, NON_SWAPPABLE, false),
+ WF(XBGR2101010, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, NON_SWAPPABLE, false),
+ WF(RGBX1010102, 32, 0xffc00000, 0x003ff000, 0x00000ffc, 0x00000003, NON_SWAPPABLE, false),
+ WF(BGRX1010102, 32, 0x00000ffc, 0x003ff000, 0xffc00000, 0x00000003, NON_SWAPPABLE, false),
+ WF(ARGB2101010, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, NON_SWAPPABLE, true),
+ WF(ABGR2101010, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, NON_SWAPPABLE, true),
+ WF(RGBA1010102, 32, 0xffc00000, 0x003ff000, 0x00000ffc, 0x00000003, NON_SWAPPABLE, true),
+ WF(BGRA1010102, 32, 0x00000ffc, 0x003ff000, 0xffc00000, 0x00000003, NON_SWAPPABLE, true)
+};
+
static uint32_t
wl_drm_format_for_vk_format(VkFormat vk_format, bool alpha)
{
- switch (vk_format) {
- /* TODO: Figure out what all the formats mean and make this table
- * correct.
- */
-#if 0
- case VK_FORMAT_R4G4B4A4_UNORM:
- return alpha ? WL_DRM_FORMAT_ABGR4444 : WL_DRM_FORMAT_XBGR4444;
- case VK_FORMAT_R5G6B5_UNORM:
- return WL_DRM_FORMAT_BGR565;
- case VK_FORMAT_R5G5B5A1_UNORM:
- return alpha ? WL_DRM_FORMAT_ABGR1555 : WL_DRM_FORMAT_XBGR1555;
- case VK_FORMAT_R8G8B8_UNORM:
- return WL_DRM_FORMAT_XBGR8888;
- case VK_FORMAT_R8G8B8A8_UNORM:
- return alpha ? WL_DRM_FORMAT_ABGR8888 : WL_DRM_FORMAT_XBGR8888;
- case VK_FORMAT_R10G10B10A2_UNORM:
- return alpha ? WL_DRM_FORMAT_ABGR2101010 : WL_DRM_FORMAT_XBGR2101010;
- case VK_FORMAT_B4G4R4A4_UNORM:
- return alpha ? WL_DRM_FORMAT_ARGB4444 : WL_DRM_FORMAT_XRGB4444;
- case VK_FORMAT_B5G6R5_UNORM:
- return WL_DRM_FORMAT_RGB565;
- case VK_FORMAT_B5G5R5A1_UNORM:
- return alpha ? WL_DRM_FORMAT_XRGB1555 : WL_DRM_FORMAT_XRGB1555;
-#endif
- case VK_FORMAT_B8G8R8_UNORM:
- case VK_FORMAT_B8G8R8_SRGB:
- return WL_DRM_FORMAT_BGRX8888;
- case VK_FORMAT_B8G8R8A8_UNORM:
- case VK_FORMAT_B8G8R8A8_SRGB:
- return alpha ? WL_DRM_FORMAT_ARGB8888 : WL_DRM_FORMAT_XRGB8888;
-#if 0
- case VK_FORMAT_B10G10R10A2_UNORM:
- return alpha ? WL_DRM_FORMAT_ARGB2101010 : WL_DRM_FORMAT_XRGB2101010;
-#endif
-
- default:
- assert(!"Unsupported Vulkan format");
- return 0;
+ struct vk_format_util_spec vspec;
+ uint32_t drm_format = 0;
+
+ vk_get_format_spec(vk_format, &vspec);
+
+ for (size_t i = 0; i < ARRAY_SIZE(drm_format_specs); i++) {
+ const struct drm_format_spec *dspec = &drm_format_specs[i];
+ if (vk_compare_format_specs(&vspec, &dspec->vspec) &&
+ dspec->has_alpha == alpha) {
+ drm_format = dspec->format;
+ break;
+ }
}
+
+ assert(drm_format != 0);
+
+ return drm_format;
}
static void
drm_handle_format(void *data, struct wl_drm *drm, uint32_t wl_format)
{
struct wsi_wl_display *display = data;
+ const struct vk_format_util_spec *vspec = NULL;
+ struct u_vector formats;
+
+ for (size_t i = 0; i < ARRAY_SIZE(drm_format_specs); i++) {
+ const struct drm_format_spec *dspec = &drm_format_specs[i];
+ if (dspec->format == wl_format) {
+ vspec = &dspec->vspec;
+ break;
+ }
+ }
+
+ if (!vspec)
+ return;
- switch (wl_format) {
-#if 0
- case WL_DRM_FORMAT_ABGR4444:
- case WL_DRM_FORMAT_XBGR4444:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_R4G4B4A4_UNORM);
- break;
- case WL_DRM_FORMAT_BGR565:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_R5G6B5_UNORM);
- break;
- case WL_DRM_FORMAT_ABGR1555:
- case WL_DRM_FORMAT_XBGR1555:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_R5G5B5A1_UNORM);
- break;
- case WL_DRM_FORMAT_XBGR8888:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_R8G8B8_UNORM);
- /* fallthrough */
- case WL_DRM_FORMAT_ABGR8888:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_R8G8B8A8_UNORM);
- break;
- case WL_DRM_FORMAT_ABGR2101010:
- case WL_DRM_FORMAT_XBGR2101010:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_R10G10B10A2_UNORM);
- break;
- case WL_DRM_FORMAT_ARGB4444:
- case WL_DRM_FORMAT_XRGB4444:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_B4G4R4A4_UNORM);
- break;
- case WL_DRM_FORMAT_RGB565:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_B5G6R5_UNORM);
- break;
- case WL_DRM_FORMAT_ARGB1555:
- case WL_DRM_FORMAT_XRGB1555:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_B5G5R5A1_UNORM);
- break;
-#endif
- case WL_DRM_FORMAT_XRGB8888:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_B8G8R8_SRGB);
- wsi_wl_display_add_vk_format(display, VK_FORMAT_B8G8R8_UNORM);
- /* fallthrough */
- case WL_DRM_FORMAT_ARGB8888:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_B8G8R8A8_SRGB);
- wsi_wl_display_add_vk_format(display, VK_FORMAT_B8G8R8A8_UNORM);
- break;
-#if 0
- case WL_DRM_FORMAT_ARGB2101010:
- case WL_DRM_FORMAT_XRGB2101010:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_B10G10R10A2_UNORM);
- break;
-#endif
+ if (!u_vector_init(&formats, sizeof(VkFormat), 8))
+ return;
+
+ vk_find_matching_formats(vspec, &formats);
+
+ VkFormat *f;
+ u_vector_foreach(f, &formats) {
+ wsi_wl_display_add_vk_format(display, *f);
}
+
+ u_vector_finish(&formats);
}
static void
--
2.11.0
More information about the mesa-dev
mailing list