[Mesa-dev] [PATCH] vulkan/wsi/wayland: Extend matching between vk and wl_drm formats
Alexandros Frantzis
alexandros.frantzis at collabora.com
Wed Oct 4 12:34:10 UTC 2017
Extend the matching from vk to wl_drm formats and vice-versa, to include
all supported RGB(A) formats. Since the memory layout of many Vulkan
formats depends on system endianness, take endianness into account when
performing the matching.
---
src/vulkan/wsi/wsi_common_wayland.c | 166 ++++++++++++++++++++++--------------
1 file changed, 102 insertions(+), 64 deletions(-)
diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c
index 4c94cd60a5..9bb1f68c1a 100644
--- a/src/vulkan/wsi/wsi_common_wayland.c
+++ b/src/vulkan/wsi/wsi_common_wayland.c
@@ -36,6 +36,7 @@
#include "wayland-drm-client-protocol.h"
#include <util/hash_table.h>
+#include <util/u_endian.h>
#include <util/u_vector.h>
#define typed_memcpy(dest, src, count) ({ \
@@ -102,45 +103,57 @@ drm_handle_device(void *data, struct wl_drm *drm, const char *name)
static uint32_t
wl_drm_format_for_vk_format(VkFormat vk_format, bool alpha)
{
+#define WL_DRM_FMT_XA(X, A) (alpha ? WL_DRM_FORMAT_ ## A : WL_DRM_FORMAT_ ## X)
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+#define WL_DRM_FMT_LE_XA(X, A) WL_DRM_FMT_XA(X, A)
+#define WL_DRM_FMT_LE_BE_XA(LE_X, LE_A, BE_X, BE_A) WL_DRM_FMT_XA(LE_X, LE_A)
+#else
+#define WL_DRM_FMT_LE_XA(X, A) 0
+#define WL_DRM_FMT_LE_BE_XA(LE_X, LE_A, BE_X, BE_A) WL_DRM_FMT_XA(BE_X, BE_A)
+#endif
+
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_R4G4B4A4_UNORM_PACK16:
+ return WL_DRM_FMT_LE_XA(RGBX4444, RGBA4444);
+ case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
+ return WL_DRM_FMT_LE_XA(BGRX4444, BGRA4444);
+ case VK_FORMAT_R5G6B5_UNORM_PACK16:
+ return WL_DRM_FMT_LE_XA(RGB565, RGB565);
+ case VK_FORMAT_B5G6R5_UNORM_PACK16:
+ return WL_DRM_FMT_LE_XA(BGR565, BGR565);
+ case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
+ return WL_DRM_FMT_LE_XA(RGBX5551, RGBA5551);
+ case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
+ return WL_DRM_FMT_LE_XA(BGRX5551, BGRA5551);
+ case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
+ return WL_DRM_FMT_LE_XA(XRGB1555, ARGB1555);
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_R8G8B8_SRGB:
+ return WL_DRM_FORMAT_BGR888;
case VK_FORMAT_B8G8R8_UNORM:
case VK_FORMAT_B8G8R8_SRGB:
- return WL_DRM_FORMAT_BGRX8888;
+ return WL_DRM_FORMAT_RGB888;
+ case VK_FORMAT_R8G8B8A8_UNORM:
+ case VK_FORMAT_R8G8B8A8_SRGB:
+ return WL_DRM_FMT_XA(XBGR8888, ABGR8888);
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
-
+ return WL_DRM_FMT_XA(XRGB8888, ARGB8888);
+ case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
+ case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
+ return WL_DRM_FMT_LE_BE_XA(XBGR8888, ABGR8888, RGBX8888, RGBA8888);
+ case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
+ return WL_DRM_FMT_LE_XA(XRGB2101010, ARGB2101010);
+ case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
+ return WL_DRM_FMT_LE_XA(XBGR2101010, ABGR2101010);
default:
assert(!"Unsupported Vulkan format");
return 0;
}
+
+#undef WL_DRM_FMT_LE_BE_XA
+#undef WL_DRM_FMT_LE_XA
+#undef WL_DRM_FMT_XA
}
static void
@@ -150,56 +163,81 @@ drm_handle_format(void *data, struct wl_drm *drm, uint32_t wl_format)
if (display->formats.element_size == 0)
return;
+#define ADD_VK_FORMAT(FMT) \
+ wsi_wl_display_add_vk_format(display, VK_FORMAT_ ## FMT)
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+#define ADD_VK_FORMAT_LE(FMT) ADD_VK_FORMAT(FMT)
+#define ADD_VK_FORMAT_BE(FMT)
+#else
+#define ADD_VK_FORMAT_LE(FMT)
+#define ADD_VK_FORMAT_BE(FMT) ADD_VK_FORMAT(FMT)
+#endif
+
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);
+ case WL_DRM_FORMAT_RGBA4444:
+ case WL_DRM_FORMAT_RGBX4444:
+ ADD_VK_FORMAT_LE(R4G4B4A4_UNORM_PACK16);
break;
- case WL_DRM_FORMAT_BGR565:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_R5G6B5_UNORM);
+ case WL_DRM_FORMAT_BGRA4444:
+ case WL_DRM_FORMAT_BGRX4444:
+ ADD_VK_FORMAT_LE(B4G4R4A4_UNORM_PACK16);
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);
+ case WL_DRM_FORMAT_XRGB1555:
+ case WL_DRM_FORMAT_ARGB1555:
+ ADD_VK_FORMAT_LE(A1R5G5B5_UNORM_PACK16);
break;
- case WL_DRM_FORMAT_ABGR2101010:
- case WL_DRM_FORMAT_XBGR2101010:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_R10G10B10A2_UNORM);
+ case WL_DRM_FORMAT_RGBX5551:
+ case WL_DRM_FORMAT_RGBA5551:
+ ADD_VK_FORMAT_LE(R5G5B5A1_UNORM_PACK16);
break;
- case WL_DRM_FORMAT_ARGB4444:
- case WL_DRM_FORMAT_XRGB4444:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_B4G4R4A4_UNORM);
+ case WL_DRM_FORMAT_BGRX5551:
+ case WL_DRM_FORMAT_BGRA5551:
+ ADD_VK_FORMAT_LE(B5G5R5A1_UNORM_PACK16);
break;
case WL_DRM_FORMAT_RGB565:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_B5G6R5_UNORM);
+ ADD_VK_FORMAT_LE(R5G6B5_UNORM_PACK16);
break;
- case WL_DRM_FORMAT_ARGB1555:
- case WL_DRM_FORMAT_XRGB1555:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_B5G5R5A1_UNORM);
+ case WL_DRM_FORMAT_BGR565:
+ ADD_VK_FORMAT_LE(B5G6R5_UNORM_PACK16);
+ break;
+ case WL_DRM_FORMAT_RGB888:
+ ADD_VK_FORMAT(B8G8R8_UNORM);
+ ADD_VK_FORMAT(B8G8R8_SRGB);
+ break;
+ case WL_DRM_FORMAT_BGR888:
+ ADD_VK_FORMAT(R8G8B8_UNORM);
+ ADD_VK_FORMAT(R8G8B8_SRGB);
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);
+ case WL_DRM_FORMAT_XRGB8888:
+ ADD_VK_FORMAT(B8G8R8A8_UNORM);
+ ADD_VK_FORMAT(B8G8R8A8_SRGB);
+ break;
+ case WL_DRM_FORMAT_ABGR8888:
+ case WL_DRM_FORMAT_XBGR8888:
+ ADD_VK_FORMAT(R8G8B8A8_UNORM);
+ ADD_VK_FORMAT(R8G8B8A8_SRGB);
+ ADD_VK_FORMAT_LE(A8B8G8R8_UNORM_PACK32);
+ ADD_VK_FORMAT_LE(A8B8G8R8_SRGB_PACK32);
+ break;
+ case WL_DRM_FORMAT_RGBA8888:
+ case WL_DRM_FORMAT_RGBX8888:
+ ADD_VK_FORMAT_BE(A8B8G8R8_UNORM_PACK32);
+ ADD_VK_FORMAT_BE(A8B8G8R8_SRGB_PACK32);
break;
-#if 0
case WL_DRM_FORMAT_ARGB2101010:
case WL_DRM_FORMAT_XRGB2101010:
- wsi_wl_display_add_vk_format(display, VK_FORMAT_B10G10R10A2_UNORM);
+ ADD_VK_FORMAT_LE(A2R10G10B10_UNORM_PACK32);
+ break;
+ case WL_DRM_FORMAT_ABGR2101010:
+ case WL_DRM_FORMAT_XBGR2101010:
+ ADD_VK_FORMAT_LE(A2B10G10R10_UNORM_PACK32);
break;
-#endif
}
+
+#undef ADD_VK_FORMAT_BE
+#undef ADD_VK_FORMAT_LE
+#undef ADD_VK_FORMAT
}
static void
--
2.14.1
More information about the mesa-dev
mailing list