From 00338d89f5caa6d6cc913b5a73325bbd1c51f1cf Mon Sep 17 00:00:00 2001 From: Normunds Rieksts Date: Tue, 26 Oct 2021 10:07:14 +0000 Subject: [PATCH] Add build option for headless extension Adds a build option that provides the ability to build the layer with or without headless extension support Change-Id: Iedefbd38daf80d84f4763ea54117ca18c7fad088 Signed-off-by: Normunds Rieksts --- CMakeLists.txt | 25 +++++++++++++++++++++---- wsi/wsi_factory.cpp | 7 +++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5abab62..523221d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ else() endif() # Build Configuration options +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)") @@ -150,6 +151,24 @@ else() list(APPEND JSON_COMMANDS COMMAND sed -i '/VK_KHR_wayland_surface/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json) endif() +# Headless +if(BUILD_WSI_HEADLESS) + add_library(wsi_headless STATIC + wsi/headless/surface_properties.cpp + wsi/headless/surface.cpp + wsi/headless/swapchain.cpp) + + target_include_directories(wsi_headless PRIVATE + ${PROJECT_SOURCE_DIR} + ${VULKAN_CXX_INCLUDE} + ${CMAKE_CURRENT_BINARY_DIR}) + + target_compile_options(wsi_headless INTERFACE "-DBUILD_WSI_HEADLESS=1") + list(APPEND LINK_WSI_LIBS wsi_headless) +else() + list(APPEND JSON_COMMANDS COMMAND sed -i '/VK_EXT_headless_surface/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json) +endif() + # Layer add_library(${PROJECT_NAME} SHARED layer/layer.cpp @@ -162,10 +181,8 @@ add_library(${PROJECT_NAME} SHARED util/log.cpp wsi/swapchain_base.cpp wsi/synchronization.cpp - wsi/wsi_factory.cpp - wsi/headless/surface_properties.cpp - wsi/headless/surface.cpp - wsi/headless/swapchain.cpp) + wsi/wsi_factory.cpp) + target_compile_definitions(${PROJECT_NAME} PRIVATE ${WSI_DEFINES}) target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${VULKAN_CXX_INCLUDE}) diff --git a/wsi/wsi_factory.cpp b/wsi/wsi_factory.cpp index 8b8b86a..a8286e8 100644 --- a/wsi/wsi_factory.cpp +++ b/wsi/wsi_factory.cpp @@ -29,7 +29,10 @@ #include "wsi_factory.hpp" #include "surface.hpp" + +#if BUILD_WSI_HEADLESS #include "headless/surface_properties.hpp" +#endif #include #include @@ -51,7 +54,9 @@ static struct wsi_extension VkExtensionProperties extension; VkIcdWsiPlatform platform; } const supported_wsi_extensions[] = { +#if BUILD_WSI_HEADLESS { { VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME, VK_EXT_HEADLESS_SURFACE_SPEC_VERSION }, VK_ICD_WSI_PLATFORM_HEADLESS }, +#endif #if BUILD_WSI_WAYLAND { { VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_SPEC_VERSION }, VK_ICD_WSI_PLATFORM_WAYLAND }, #endif @@ -61,8 +66,10 @@ static surface_properties *get_surface_properties(VkIcdWsiPlatform platform) { switch (platform) { +#if BUILD_WSI_HEADLESS case VK_ICD_WSI_PLATFORM_HEADLESS: return &headless::surface_properties::get_instance(); +#endif #if BUILD_WSI_WAYLAND case VK_ICD_WSI_PLATFORM_WAYLAND: return &wayland::surface_properties::get_instance();