mirror of
https://gitlab.freedesktop.org/mesa/vulkan-wsi-layer.git
synced 2025-12-30 07:10:10 +01:00
Add versioning to wsialloc interface
The wsialloc interface now has explicit versioning which is used to ensure that wsialloc implementations are compatible with the interface. wsialloc implementations should define which version they are using and upon version mismatch compilation will fail. Also: - add new WSIALLOC_MAX_PLANE macro to define the maximum number of planes that the wsialloc should support. Change-Id: I211fc4341f249deff0c005d946c483ba47366600 Signed-off-by: Dennis Tsiang <dennis.tsiang@arm.com>
This commit is contained in:
parent
0ef73036aa
commit
1701c1fea4
5 changed files with 58 additions and 9 deletions
|
|
@ -80,10 +80,11 @@ if(BUILD_DRM_UTILS)
|
|||
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_include_directories(drm_utils PUBLIC util/wsialloc)
|
||||
target_compile_options(drm_utils PUBLIC ${LIBDRM_CFLAGS})
|
||||
endif()
|
||||
|
||||
# External WSI Alloctator
|
||||
# External WSI Allocator
|
||||
if(NOT SELECT_EXTERNAL_ALLOCATOR STREQUAL "none" AND EXTERNAL_WSIALLOC_LIBRARY STREQUAL "")
|
||||
add_library(wsialloc STATIC)
|
||||
set_target_properties(wsialloc PROPERTIES C_STANDARD 99)
|
||||
|
|
|
|||
|
|
@ -26,22 +26,20 @@
|
|||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <drm_fourcc.h>
|
||||
#include "wsialloc.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];
|
||||
uint8_t bpp[WSIALLOC_MAX_PLANES];
|
||||
VkFormat vk_format;
|
||||
} fmt_spec;
|
||||
|
||||
|
|
|
|||
|
|
@ -53,8 +53,43 @@ extern "C" {
|
|||
* All API Public entry points are implemented in a way that is thread safe, and the client does not need to be
|
||||
* concerned with locking when using these APIs. If implementers make use of non-threadsafe functions, writable global
|
||||
* data etc they must make appropriate use of locks.
|
||||
*
|
||||
* Version History:
|
||||
* 1 - Initial wsialloc interface
|
||||
*/
|
||||
|
||||
#define WSIALLOC_INTERFACE_VERSION 1
|
||||
|
||||
#define WSIALLOC_CONCAT(x, y) x##y
|
||||
#define WSIALLOC_SYMBOL_VERSION(symbol, version) WSIALLOC_CONCAT(symbol, version)
|
||||
|
||||
/**
|
||||
* @brief This symbol must be defined by any implementation of the wsialloc interface as defined in this header.
|
||||
*
|
||||
* A wsialloc implementation defining this symbol is declaring it implements
|
||||
* the exact version of the wsialloc interface defined in this header.
|
||||
*/
|
||||
#define WSIALLOC_IMPLEMENTATION_VERSION_SYMBOL \
|
||||
WSIALLOC_SYMBOL_VERSION(wsialloc_symbol_version_, WSIALLOC_INTERFACE_VERSION)
|
||||
extern const uint32_t WSIALLOC_IMPLEMENTATION_VERSION_SYMBOL;
|
||||
|
||||
/**
|
||||
* @brief Aborts if the wsialloc implementation version is not the expected one.
|
||||
*
|
||||
* This macro calls abort() if the version of the wsialloc implementation that was linked to the code using this
|
||||
* macro is not matching the version defined in the wsialloc.h header that is being included. This can be useful
|
||||
* to catch compatibility issues in code that links to an external static library implementing the wsialloc
|
||||
* interface.
|
||||
*/
|
||||
#define WSIALLOC_ASSERT_VERSION() \
|
||||
if (WSIALLOC_IMPLEMENTATION_VERSION_SYMBOL != WSIALLOC_INTERFACE_VERSION) \
|
||||
{ \
|
||||
abort(); \
|
||||
}
|
||||
|
||||
/* Maximum number of planes that can be returned */
|
||||
#define WSIALLOC_MAX_PLANES 4
|
||||
|
||||
/**
|
||||
* @brief Allocator type.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -39,6 +39,20 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* @brief Version of the wsialloc interface we are implementing in this file.
|
||||
*
|
||||
* This should only be increased when this implementation is updated to match newer versions of wsialloc.h.
|
||||
*/
|
||||
#define WSIALLOC_IMPLEMENTATION_VERSION 1
|
||||
|
||||
/* Ensure we are implementing the wsialloc version matching the wsialloc.h header we are using. */
|
||||
#if WSIALLOC_IMPLEMENTATION_VERSION != WSIALLOC_INTERFACE_VERSION
|
||||
#error "Version mismatch between wsialloc implementation and interface version"
|
||||
#endif
|
||||
|
||||
const uint32_t WSIALLOC_IMPLEMENTATION_VERSION_SYMBOL = WSIALLOC_IMPLEMENTATION_VERSION;
|
||||
|
||||
/** Default alignment */
|
||||
#define WSIALLOCP_MIN_ALIGN_SZ (64u)
|
||||
/** Maximum image size allowed for each dimension */
|
||||
|
|
@ -252,7 +266,7 @@ static const fmt_spec *find_format(uint32_t fourcc)
|
|||
if (fourcc == fourcc_format_table[i].drm_format)
|
||||
{
|
||||
const fmt_spec *found_fmt = &fourcc_format_table[i];
|
||||
assert(found_fmt->nr_planes <= WSIALLOCP_MAX_PLANES);
|
||||
assert(found_fmt->nr_planes <= WSIALLOC_MAX_PLANES);
|
||||
|
||||
return found_fmt;
|
||||
}
|
||||
|
|
@ -298,9 +312,9 @@ wsialloc_error wsialloc_alloc(wsialloc_allocator *allocator, const wsialloc_allo
|
|||
return WSIALLOC_ERROR_INVALID;
|
||||
}
|
||||
|
||||
int local_strides[WSIALLOCP_MAX_PLANES];
|
||||
int local_fds[WSIALLOCP_MAX_PLANES] = { -1 };
|
||||
int local_offsets[WSIALLOCP_MAX_PLANES];
|
||||
int local_strides[WSIALLOC_MAX_PLANES];
|
||||
int local_fds[WSIALLOC_MAX_PLANES] = { -1 };
|
||||
int local_offsets[WSIALLOC_MAX_PLANES];
|
||||
wsialloc_error err = WSIALLOC_ERROR_NONE;
|
||||
wsialloc_format_descriptor selected_format_desc = {};
|
||||
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ VkResult swapchain::init_platform(VkDevice device, const VkSwapchainCreateInfoKH
|
|||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
}
|
||||
|
||||
WSIALLOC_ASSERT_VERSION();
|
||||
if (wsialloc_new(&m_wsi_allocator) != WSIALLOC_ERROR_NONE)
|
||||
{
|
||||
WSI_LOG_ERROR("Failed to create wsi allocator.");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue