Commit 8dc4d923 authored by Iason Paraskevopoulos's avatar Iason Paraskevopoulos
Browse files

Adds initial support for VK_KHR_wayland_surface.



Very basic Wayland support is implemented by importing
memory with VK_EXT_image_drm_format_modifiers.
The current implementation requires an external system
memory allocator. An API for this allocator is defined
in util/wsialloc/wsialloc.h and an implementation using
the ION memory allocator is included.

Outstanding issues:
 * This is an initial prototype for Wayland support and
   has many outstanding TODOs which need addressing to
   properly use the Wayland protocol.
 * Using ICD Exported memory instead of a system allocator
   is not implemented.

Wayland support is still experimental and outstanding issues
will be fixed in future commits.

Change-Id: I1b0d5991e15ff1cf25ebbab3392a631b021e8c17
Signed-off-by: Rosen's avatarRosen Zhelev <rosen.zhelev@arm.com>
Signed-off-by: Iason Paraskevopoulos's avatarIason Paraskevopoulos <iason.paraskevopoulos@arm.com>
parent 950cdd40
Pipeline #268879 passed with stage
in 1 minute and 17 seconds
......@@ -20,16 +20,18 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 2.8.11)
project(VkLayer_window_system_integration CXX)
cmake_minimum_required(VERSION 3.4.3)
project(VkLayer_window_system_integration)
find_package(PkgConfig REQUIRED)
pkg_check_modules(VULKAN_PKG_CONFIG vulkan)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pthread -fPIC")
if (DEFINED DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
......@@ -44,6 +46,101 @@ else()
message(FATAL_ERROR "Either vulkan.pc must be available or VULKAN_CXX_INCLUDE must be defined")
endif()
# Build Configuration options
option(BUILD_WSI_WAYLAND "Build with support for VK_KHR_wayland_surface" OFF)
set(SELECT_EXTERNAL_ALLOCATOR "none" CACHE STRING "Select an external system allocator (none, ion)")
if(BUILD_WSI_WAYLAND)
if(SELECT_EXTERNAL_ALLOCATOR STREQUAL "none")
message(FATAL_ERROR "Wayland only supported with an external allocator.")
endif()
set(BUILD_DRM_UTILS True)
endif()
# DRM Utilities
if(BUILD_DRM_UTILS)
add_library(drm_utils STATIC util/drm/drm_utils.cpp)
pkg_check_modules(LIBDRM REQUIRED libdrm)
message(STATUS "Using libdrm include directories: ${LIBDRM_INCLUDE_DIRS}")
message(STATUS "Using libdrm cflags: ${LIBDRM_CFLAGS}")
target_sources(drm_utils PRIVATE util/drm/format_table.c)
target_include_directories(drm_utils PRIVATE ${VULKAN_CXX_INCLUDE})
target_include_directories(drm_utils PUBLIC ${LIBDRM_INCLUDE_DIRS})
target_compile_options(drm_utils PUBLIC ${LIBDRM_CFLAGS})
endif()
# External WSI Alloctator
if(NOT SELECT_EXTERNAL_ALLOCATOR STREQUAL "none")
add_library(wsialloc STATIC)
set_target_properties(wsialloc PROPERTIES C_STANDARD 99)
if(SELECT_EXTERNAL_ALLOCATOR STREQUAL "ion")
target_sources(wsialloc PRIVATE util/wsialloc/wsialloc_ion.c)
target_link_libraries(wsialloc drm_utils)
if(DEFINED KERNEL_DIR)
target_include_directories(wsialloc PRIVATE "${KERNEL_DIR}/drivers/staging/android/uapi")
else()
message(FATAL_ERROR "KERNEL_DIR must be defined as the root of the Linux kernel source.")
endif()
else()
message(FATAL_ERROR "Invalid external allocator selected: ${SELECT_EXTERNAL_ALLOCATOR}")
endif()
target_include_directories(wsialloc PRIVATE ${VULKAN_CXX_INCLUDE})
target_include_directories(wsialloc PRIVATE util/drm)
endif()
# Wayland WSI
if(BUILD_WSI_WAYLAND)
add_library(wayland_wsi STATIC
wsi/wayland/surface_properties.cpp
wsi/wayland/swapchain_wl_helpers.cpp
wsi/wayland/swapchain.cpp)
pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client)
message(STATUS "Using Wayland client include directories: ${WAYLAND_CLIENT_INCLUDE_DIRS}")
message(STATUS "Using Wayland client cflags: ${WAYLAND_CLIENT_CFLAGS}")
message(STATUS "Using Wayland client ldflags: ${WAYLAND_CLIENT_LDFLAGS}")
pkg_check_modules(WAYLAND_SCANNER REQUIRED wayland-scanner)
pkg_get_variable(WAYLAND_SCANNER_EXEC wayland-scanner wayland_scanner)
message(STATUS "Using wayland-scanner : ${WAYLAND_SCANNER_EXEC}")
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
message(STATUS "Using wayland protocols dir : ${WAYLAND_PROTOCOLS_DIR}")
add_custom_target(wayland_generated_files
COMMAND ${WAYLAND_SCANNER_EXEC} client-header
${WAYLAND_PROTOCOLS_DIR}/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml
${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-client-protocol.h
COMMAND ${WAYLAND_SCANNER_EXEC} code
${WAYLAND_PROTOCOLS_DIR}/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml
${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-protocol.c
BYPRODUCTS linux-dmabuf-unstable-v1-protocol.c linux-dmabuf-unstable-v1-client-protocol.h)
target_sources(wayland_wsi PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-protocol.c
${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-client-protocol.h)
add_dependencies(wayland_wsi wayland_generated_files)
target_include_directories(wayland_wsi PRIVATE
${PROJECT_SOURCE_DIR}
${VULKAN_CXX_INCLUDE}
${WAYLAND_CLIENT_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR})
target_compile_options(wayland_wsi PRIVATE ${WAYLAND_CLIENT_CFLAGS})
target_compile_options(wayland_wsi INTERFACE "-DBUILD_WSI_WAYLAND=1")
target_link_libraries(wayland_wsi drm_utils wsialloc ${WAYLAND_CLIENT_LDFLAGS})
list(APPEND LINK_WSI_LIBS wayland_wsi)
else()
list(APPEND JSON_COMMANDS COMMAND sed -i '/VK_KHR_wayland_surface/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json)
endif()
# Layer
add_library(${PROJECT_NAME} SHARED
layer/layer.cpp
layer/private_data.cpp
......@@ -56,5 +153,12 @@ add_library(${PROJECT_NAME} SHARED
wsi/wsi_factory.cpp
wsi/headless/surface_properties.cpp
wsi/headless/swapchain.cpp)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11)
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR} ${VULKAN_CXX_INCLUDE})
target_compile_definitions(${PROJECT_NAME} PRIVATE ${WSI_DEFINES})
target_include_directories(${PROJECT_NAME} PRIVATE
${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${VULKAN_CXX_INCLUDE})
target_link_libraries(${PROJECT_NAME} ${LINK_WSI_LIBS})
add_custom_target(manifest_json ALL COMMAND
cp ${PROJECT_SOURCE_DIR}/layer/VkLayer_window_system_integration.json ${CMAKE_CURRENT_BINARY_DIR}
${JSON_COMMANDS})
......@@ -12,14 +12,14 @@ ICD; instead, the implementation of these extensions are shared across vendors
for mutual benefit.
The project currently implements support for `VK_EXT_headless_surface` and
its dependencies. We hope to extend support for further platforms such as Wayland
and direct-to-display rendering in the future.
its dependencies. Experimental support for `VK_KHR_wayland_surface` can be
enabled via a build option [as explained below](#building-with-wayland-support).
## Building
### Dependencies
* [CMake](https://cmake.org) version 2.8.11 or above.
* [CMake](https://cmake.org) version 3.4.3 or above.
* C++11 compiler.
* Vulkan® loader and associated headers with support for the
`VK_EXT_headless_surface` extension.
......@@ -59,6 +59,23 @@ cmake . -Bbuild
make -C build
```
#### Building with Wayland support
In order to build with Wayland support the `BUILD_WSI_WAYLAND` build option
must be used, the `SELECT_EXTERNAL_ALLOCATOR` option has to be set to
an allocator (currently only ion is supported) and the `KERNEL_DIR` option must
be defined as the root of the Linux kernel source.
```
cmake . -DVULKAN_CXX_INCLUDE="path/to/vulkan-header" \
-DBUILD_WSI_WAYLAND=1 \
-DSELECT_EXTERNAL_ALLOCATOR=ion \
-DKERNEL_DIR="path/to/linux-kernel-source"
```
Wayland support is still **EXPERIMENTAL**. What this means in practice is that
the support is incomplete and not ready for prime time.
## Installation
Copy the shared library `libVkLayer_window_system_integration.so` and JSON
......
{
"file_format_version" : "1.0.0",
"file_format_version" : "1.1.2",
"layer" : {
"name": "VK_LAYER_window_system_integration",
"type": "GLOBAL",
......@@ -11,15 +11,13 @@
"vkGetInstanceProcAddr": "wsi_layer_vkGetInstanceProcAddr",
"vkGetDeviceProcAddr": "wsi_layer_vkGetDeviceProcAddr"
},
"pre_instance_functions" : {
"vkEnumerateInstanceExtensionProperties" : "wsi_layer_vkEnumerateInstanceExtensionProperties"
},
"instance_extensions": [
{
"name" : "VK_EXT_headless_surface",
"spec_version" : "1"
},
{
"name" : "VK_KHR_surface",
"spec_version" : "1"
}
{"name" : "VK_EXT_headless_surface", "spec_version" : "1"},
{"name" : "VK_KHR_wayland_surface", "spec_version" : "1"},
{"name" : "VK_KHR_surface", "spec_version" : "1"}
],
"device_extensions": [
{
......@@ -28,10 +26,10 @@
}
],
"enable_environment": {
"ENABLE_HEADLESS_SURFACE": "1"
"ENABLE_WSI_LAYER": "1"
},
"disable_environment": {
"DISABLE_HEADLESS_SURFACE": "1"
"DISABLE_WSI_LAYER": "1"
}
}
}
......@@ -60,7 +60,7 @@ VKAPI_ATTR VkResult extension_properties(const uint32_t count, const VkExtension
}
size = *pCount < count ? *pCount : count;
memcpy(pProp, layer_ext, size * sizeof(VkExtensionProperties));
memcpy(pProp, layer_ext, size * sizeof(*pProp));
*pCount = size;
if (size < count)
{
......@@ -82,7 +82,7 @@ VKAPI_ATTR VkResult layer_properties(const uint32_t count, const VkLayerProperti
}
size = *pCount < count ? *pCount : count;
memcpy(pProp, layer_prop, size * sizeof(VkLayerProperties));
memcpy(pProp, layer_prop, size * sizeof(*pProp));
*pCount = size;
if (size < count)
{
......@@ -333,12 +333,14 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL wsi_layer_vkEnumerateDeviceExtens
}
VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL wsi_layer_vkEnumerateInstanceExtensionProperties(
const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties)
const VkEnumerateInstanceExtensionPropertiesChain *chain, const char *pLayerName,
uint32_t *pCount, VkExtensionProperties *pProperties)
{
if (pLayerName && !strcmp(pLayerName, layer::global_layer.layerName))
return layer::extension_properties(1, layer::instance_extension, pCount, pProperties);
return VK_ERROR_LAYER_NOT_PRESENT;
assert(chain);
return chain->CallDown(pLayerName, pCount, pProperties);
}
VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
......@@ -365,6 +367,12 @@ VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI_CALL wsi_layer_vkGetDeviceProcAddr(VkDe
VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL wsi_layer_vkGetInstanceProcAddr(VkInstance instance,
const char *funcName)
{
PFN_vkVoidFunction wsi_func = wsi::get_proc_addr(funcName);
if (wsi_func)
{
return wsi_func;
}
GET_PROC_ADDR(vkGetDeviceProcAddr);
GET_PROC_ADDR(vkGetInstanceProcAddr);
GET_PROC_ADDR(vkCreateInstance);
......@@ -376,7 +384,6 @@ VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL wsi_layer_vkGetInstance
GET_PROC_ADDR(vkGetPhysicalDeviceSurfaceFormatsKHR);
GET_PROC_ADDR(vkGetPhysicalDeviceSurfacePresentModesKHR);
GET_PROC_ADDR(vkEnumerateDeviceExtensionProperties);
GET_PROC_ADDR(vkEnumerateInstanceExtensionProperties);
GET_PROC_ADDR(vkEnumerateInstanceLayerProperties);
return layer::instance_private_data::get(instance).disp.GetInstanceProcAddr(instance, funcName);
......
......@@ -214,4 +214,4 @@ void device_private_data::destroy(VkDevice dev)
scoped_mutex lock(g_data_lock);
g_device_data.erase(get_key(dev));
}
} /* namespace layer */
\ No newline at end of file
} /* namespace layer */
......@@ -45,16 +45,17 @@ namespace layer
* guarantee than we can safely call them. We still mark the entrypoints with REQUIRED() and OPTIONAL(). The layer
* fails if vkGetInstanceProcAddr returns null for entrypoints that are REQUIRED().
*/
#define INSTANCE_ENTRYPOINTS_LIST(REQUIRED, OPTIONAL) \
REQUIRED(GetInstanceProcAddr) \
REQUIRED(DestroyInstance) \
REQUIRED(GetPhysicalDeviceProperties) \
REQUIRED(GetPhysicalDeviceImageFormatProperties) \
REQUIRED(EnumerateDeviceExtensionProperties) \
OPTIONAL(GetPhysicalDeviceSurfaceCapabilitiesKHR) \
OPTIONAL(GetPhysicalDeviceSurfaceFormatsKHR) \
OPTIONAL(GetPhysicalDeviceSurfacePresentModesKHR) \
OPTIONAL(GetPhysicalDeviceSurfaceSupportKHR)
#define INSTANCE_ENTRYPOINTS_LIST(REQUIRED, OPTIONAL) \
REQUIRED(GetInstanceProcAddr) \
REQUIRED(DestroyInstance) \
REQUIRED(GetPhysicalDeviceProperties) \
REQUIRED(GetPhysicalDeviceImageFormatProperties) \
REQUIRED(EnumerateDeviceExtensionProperties) \
OPTIONAL(GetPhysicalDeviceSurfaceCapabilitiesKHR) \
OPTIONAL(GetPhysicalDeviceSurfaceFormatsKHR) \
OPTIONAL(GetPhysicalDeviceSurfacePresentModesKHR) \
OPTIONAL(GetPhysicalDeviceSurfaceSupportKHR) \
OPTIONAL(GetPhysicalDeviceImageFormatProperties2KHR)
struct instance_dispatch_table
{
......@@ -100,7 +101,8 @@ struct instance_dispatch_table
OPTIONAL(DestroySwapchainKHR) \
OPTIONAL(GetSwapchainImagesKHR) \
OPTIONAL(AcquireNextImageKHR) \
OPTIONAL(QueuePresentKHR)
OPTIONAL(QueuePresentKHR) \
OPTIONAL(GetMemoryFdPropertiesKHR)
struct device_dispatch_table
{
......
......@@ -34,30 +34,30 @@
extern "C" {
/**
* @brief Implements vkGetPhysicalDeviceSurfaceCapabilitiesKHR Vulkan entrypoint.
*/
* @brief Implements vkGetPhysicalDeviceSurfaceCapabilitiesKHR Vulkan entrypoint.
*/
VKAPI_ATTR VkResult wsi_layer_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
VkSurfaceKHR surface,
VkSurfaceCapabilitiesKHR *pSurfaceCapabilities);
/**
* @brief Implements vkGetPhysicalDeviceSurfaceFormatsKHR Vulkan entrypoint.
*/
* @brief Implements vkGetPhysicalDeviceSurfaceFormatsKHR Vulkan entrypoint.
*/
VKAPI_ATTR VkResult wsi_layer_vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,
VkSurfaceKHR surface, uint32_t *pSurfaceFormatCount,
VkSurfaceFormatKHR *pSurfaceFormats);
/**
* @brief Implements vkGetPhysicalDeviceSurfacePresentModesKHR Vulkan entrypoint.
*/
* @brief Implements vkGetPhysicalDeviceSurfacePresentModesKHR Vulkan entrypoint.
*/
VKAPI_ATTR VkResult wsi_layer_vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
VkSurfaceKHR surface,
uint32_t *pPresentModeCount,
VkPresentModeKHR *pPresentModes);
/**
* @brief Implements vkGetPhysicalDeviceSurfaceSupportKHR Vulkan entrypoint.
*/
* @brief Implements vkGetPhysicalDeviceSurfaceSupportKHR Vulkan entrypoint.
*/
VKAPI_ATTR VkResult wsi_layer_vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
uint32_t queueFamilyIndex, VkSurfaceKHR surface,
VkBool32 *pSupported);
......
/*
* Copyright (c) 2019, 2021 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "drm_utils.hpp"
#include "format_table.h"
namespace util
{
namespace drm
{
uint32_t vk_to_drm_format(VkFormat vk_format)
{
for (size_t i = 0; i < fourcc_format_table_len; i++)
{
if (vk_format == fourcc_format_table[i].vk_format)
{
return fourcc_format_table[i].drm_format;
}
}
for (size_t i = 0; i < srgb_fourcc_format_table_len; i++)
{
if (vk_format == srgb_fourcc_format_table[i].vk_format)
{
return srgb_fourcc_format_table[i].drm_format;
}
}
return 0;
}
VkFormat drm_to_vk_format(uint32_t drm_format)
{
for (size_t i = 0; i < fourcc_format_table_len; i++)
{
if (drm_format == fourcc_format_table[i].drm_format)
{
return fourcc_format_table[i].vk_format;
}
}
return VK_FORMAT_UNDEFINED;
}
VkFormat drm_to_vk_srgb_format(uint32_t drm_format)
{
for (size_t i = 0; i < srgb_fourcc_format_table_len; i++)
{
if (drm_format == srgb_fourcc_format_table[i].drm_format)
{
return srgb_fourcc_format_table[i].vk_format;
}
}
return VK_FORMAT_UNDEFINED;
}
} // namespace drm
} // namespace util
/*
* Copyright (c) 2019, 2021 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
#include <vulkan/vulkan.h>
namespace util
{
namespace drm
{
uint32_t vk_to_drm_format(VkFormat vk_format);
VkFormat drm_to_vk_format(uint32_t drm_format);
VkFormat drm_to_vk_srgb_format(uint32_t drm_format);
} // namespace drm
} // namespace util
/*
* Copyright (c) 2021 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "format_table.h"
const fmt_spec fourcc_format_table[] = {
/* Supported R,G,B,A formats */
{ DRM_FORMAT_RGB332, 1, { 8, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_BGR233, 1, { 8, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_XRGB4444, 1, { 16, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_XBGR4444, 1, { 16, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_RGBX4444, 1, { 16, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_BGRX4444, 1, { 16, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_ARGB4444, 1, { 16, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_ABGR4444, 1, { 16, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_RGBA4444, 1, { 16, 0, 0, 0 }, VK_FORMAT_R4G4B4A4_UNORM_PACK16 },
{ DRM_FORMAT_BGRA4444, 1, { 16, 0, 0, 0 }, VK_FORMAT_B4G4R4A4_UNORM_PACK16 },
{ DRM_FORMAT_XRGB1555, 1, { 16, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_XBGR1555, 1, { 16, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_RGBX5551, 1, { 16, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_BGRX5551, 1, { 16, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_ARGB1555, 1, { 16, 0, 0, 0 }, VK_FORMAT_A1R5G5B5_UNORM_PACK16 },
{ DRM_FORMAT_ABGR1555, 1, { 16, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_RGBA5551, 1, { 16, 0, 0, 0 }, VK_FORMAT_R5G5B5A1_UNORM_PACK16 },
{ DRM_FORMAT_BGRA5551, 1, { 16, 0, 0, 0 }, VK_FORMAT_B5G5R5A1_UNORM_PACK16 },
{ DRM_FORMAT_RGB565, 1, { 16, 0, 0, 0 }, VK_FORMAT_R5G6B5_UNORM_PACK16 },
{ DRM_FORMAT_BGR565, 1, { 16, 0, 0, 0 }, VK_FORMAT_B5G6R5_UNORM_PACK16 },
{ DRM_FORMAT_RGB888, 1, { 24, 0, 0, 0 }, VK_FORMAT_B8G8R8_UNORM },
{ DRM_FORMAT_BGR888, 1, { 24, 0, 0, 0 }, VK_FORMAT_R8G8B8_UNORM },
{ DRM_FORMAT_XRGB8888, 1, { 32, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_XBGR8888, 1, { 32, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_RGBX8888, 1, { 32, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_BGRX8888, 1, { 32, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_ARGB8888, 1, { 32, 0, 0, 0 }, VK_FORMAT_B8G8R8A8_UNORM },
{ DRM_FORMAT_ABGR8888, 1, { 32, 0, 0, 0 }, VK_FORMAT_R8G8B8A8_UNORM },
{ DRM_FORMAT_RGBA8888, 1, { 32, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
{ DRM_FORMAT_BGRA8888, 1, { 32, 0, 0, 0 }, VK_FORMAT_UNDEFINED },
};
const fmt_spec srgb_fourcc_format_table[] = {
{ DRM_FORMAT_ARGB8888, 1, { 32, 0, 0, 0 }, VK_FORMAT_B8G8R8A8_SRGB },
{ DRM_FORMAT_ABGR8888, 1, { 32, 0, 0, 0 }, VK_FORMAT_R8G8B8A8_SRGB },
};
const size_t fourcc_format_table_len = NELEMS(fourcc_format_table);
const size_t srgb_fourcc_format_table_len = NELEMS(srgb_fourcc_format_table);
/*
* Copyright (c) 2021 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
#include <vulkan/vulkan.h>
#include <drm_fourcc.h>
/* Define DRM linear modifier for compatibility with older DRM header versions. */
#ifndef DRM_FORMAT_MOD_LINEAR
#define DRM_FORMAT_MOD_LINEAR 0
#endif
/* Maximum number of planes that can be returned */
#define WSIALLOCP_MAX_PLANES 4
#define NELEMS(x) (sizeof(x) / sizeof(x[0]))
typedef struct fmt_spec
{
uint32_t drm_format;
uint32_t nr_planes;
uint8_t bpp[WSIALLOCP_MAX_PLANES];
VkFormat vk_format;
} fmt_spec;
extern const fmt_spec fourcc_format_table[];
extern const fmt_spec srgb_fourcc_format_table[];
extern size_t const fourcc_format_table_len;
extern size_t const srgb_fourcc_format_table_len;
/*
* Copyright (c) 2017, 2019, 2021 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*