From 02203b8412700469d937b9cfc9c098c66d489f9c Mon Sep 17 00:00:00 2001 From: Normunds Rieksts Date: Mon, 4 Oct 2021 12:30:14 +0100 Subject: [PATCH] Add ability to specify custom wsialloc implementations Adds the ability to link the project with a custom wsialloc library. This makes it possible to customize the format selection and allocation to the target system, according to its capabilities. Change-Id: Iade5cd27aa3515d3debb7fe1f2b96453776d77be Signed-off-by: Normunds Rieksts --- CMakeLists.txt | 11 +++++++++-- wsi/wayland/swapchain.cpp | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 523221d..665c092 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ pkg_check_modules(VULKAN_PKG_CONFIG vulkan) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pthread -fPIC") if (DEFINED DEBUG) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0") endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") set(CMAKE_CXX_STANDARD 11) @@ -50,6 +51,7 @@ endif() option(BUILD_WSI_HEADLESS "Build with support for VK_EXT_headless_surface" ON) 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)") +set(EXTERNAL_WSIALLOC_LIBRARY "" CACHE STRING "External implementation of the wsialloc interface to use") if(BUILD_WSI_WAYLAND) if(SELECT_EXTERNAL_ALLOCATOR STREQUAL "none") @@ -73,7 +75,7 @@ if(BUILD_DRM_UTILS) endif() # External WSI Alloctator -if(NOT SELECT_EXTERNAL_ALLOCATOR STREQUAL "none") +if(NOT SELECT_EXTERNAL_ALLOCATOR STREQUAL "none" AND EXTERNAL_WSIALLOC_LIBRARY STREQUAL "") add_library(wsialloc STATIC) set_target_properties(wsialloc PROPERTIES C_STANDARD 99) @@ -145,7 +147,12 @@ if(BUILD_WSI_WAYLAND) 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}) + if(NOT EXTERNAL_WSIALLOC_LIBRARY STREQUAL "") + target_link_libraries(wayland_wsi ${EXTERNAL_WSIALLOC_LIBRARY}) + else() + target_link_libraries(wayland_wsi wsialloc) + endif() + target_link_libraries(wayland_wsi drm_utils ${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) diff --git a/wsi/wayland/swapchain.cpp b/wsi/wayland/swapchain.cpp index 57f2bad..52ace6f 100644 --- a/wsi/wayland/swapchain.cpp +++ b/wsi/wayland/swapchain.cpp @@ -90,7 +90,10 @@ swapchain::~swapchain() { teardown(); - wsialloc_delete(m_wsi_allocator); + if (m_wsi_allocator != nullptr) + { + wsialloc_delete(m_wsi_allocator); + } m_wsi_allocator = nullptr; if (m_swapchain_queue != nullptr) { @@ -146,9 +149,16 @@ extern "C" void create_succeeded(void *data, struct zwp_linux_buffer_params_v1 * { auto wayland_buffer = reinterpret_cast(data); *wayland_buffer = buffer; + + zwp_linux_buffer_params_v1_destroy(params); +} + +extern "C" void create_failed(void *data, struct zwp_linux_buffer_params_v1 *params) +{ + zwp_linux_buffer_params_v1_destroy(params); } -static const struct zwp_linux_buffer_params_v1_listener params_listener = { create_succeeded, NULL }; +static const struct zwp_linux_buffer_params_v1_listener params_listener = { create_succeeded, create_failed }; extern "C" void buffer_release(void *data, struct wl_buffer *wayl_buffer) { @@ -615,7 +625,7 @@ VkResult swapchain::create_and_bind_swapchain_image(VkImageCreateInfo image_crea /* should now have a wl_buffer */ assert(image_data->buffer); - zwp_linux_buffer_params_v1_destroy(params); + wl_proxy_set_queue(reinterpret_cast(image_data->buffer), m_buffer_queue); res = wl_buffer_add_listener(image_data->buffer, &buffer_listener, this); if (res < 0) -- 2.34.1