diff --git a/CMakeLists.txt b/CMakeLists.txt index 8409a89..49bc533 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_C_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) if(NOT DEFINED VULKAN_CXX_INCLUDE) set(VULKAN_CXX_INCLUDE ${VULKAN_PKG_CONFIG_INCLUDEDIR}) @@ -338,6 +339,10 @@ else() add_definitions("-DVULKAN_WSI_LAYER_EXPERIMENTAL=0") endif() + +if((CMAKE_BUILD_TYPE MATCHES "^[Dd]ebug$") OR (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")) + target_sources(${PROJECT_NAME} PUBLIC util/debug.cpp) +endif() 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/README.md b/README.md index ea8c438..5ed25f1 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,16 @@ for applications that do not make use of this extension. In order to enable this feature `-DENABLE_INSTRUMENTATION=1` option can be passed at build time. +### Debug builds + +The layer can be built with different values of the CMAKE_BUILD_TYPE variable. +When CMAKE_BUILD_TYPE is set to Debug, additional debugging functionality is enabled. +For example, internal values stored inside the layer's different objects can be retrieved. +These functions can be linked at runtime using dynamic loading mechanisms, such as dlsym(), +with the provided layer shared library. +The debug interface provides functions including: + * vk_wsi_layer_debug_get_sc_image_drm_mod + ## Installation Copy the shared library `libVkLayer_window_system_integration.so` and JSON diff --git a/util/debug.cpp b/util/debug.cpp new file mode 100644 index 0000000..07c0d16 --- /dev/null +++ b/util/debug.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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 "debug.hpp" +#include + +void vk_wsi_layer_debug_get_sc_image_drm_mod(VkSwapchainKHR swapchain, uint64_t *modifier) +{ + assert(swapchain != VK_NULL_HANDLE); + auto *sc = reinterpret_cast(swapchain); + *modifier = sc->get_modifier(); +} diff --git a/util/debug.hpp b/util/debug.hpp new file mode 100644 index 0000000..cd46aa3 --- /dev/null +++ b/util/debug.hpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 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 + +extern "C" { + +/** + * @brief Exposing the DRM modifier value of the swapchain images buffers. + * + * @param[in] swapchain The swapchain holding the image. + * @param[out] modifier The DRM modifier of the image buffer. + */ +__attribute__((visibility("default"))) void vk_wsi_layer_debug_get_sc_image_drm_mod(VkSwapchainKHR swapchain, + uint64_t *modifier); +} \ No newline at end of file diff --git a/wsi/display/swapchain.cpp b/wsi/display/swapchain.cpp index d4ba5a6..55d4c57 100644 --- a/wsi/display/swapchain.cpp +++ b/wsi/display/swapchain.cpp @@ -74,6 +74,11 @@ static void page_flip_event(int fd, unsigned int sequence, unsigned int tv_sec, *done = true; } +uint64_t swapchain::get_modifier() +{ + return m_image_creation_parameters.m_allocated_format.modifier; +} + VkResult swapchain::add_required_extensions(VkDevice device, const VkSwapchainCreateInfoKHR *swapchain_create_info) { auto compression_control = wsi_ext_image_compression_control::create(device, swapchain_create_info); diff --git a/wsi/display/swapchain.hpp b/wsi/display/swapchain.hpp index 199d177..bc47db2 100644 --- a/wsi/display/swapchain.hpp +++ b/wsi/display/swapchain.hpp @@ -125,6 +125,8 @@ protected: const VkSwapchainCreateInfoKHR &swapchain_create_info, util::vector> *extensions) override; + uint64_t get_modifier() override; + private: VkResult allocate_image(display_image_data *image_data); diff --git a/wsi/headless/swapchain.cpp b/wsi/headless/swapchain.cpp index 9cd1b92..eece153 100644 --- a/wsi/headless/swapchain.cpp +++ b/wsi/headless/swapchain.cpp @@ -142,6 +142,11 @@ VkResult swapchain::init_platform(VkDevice device, const VkSwapchainCreateInfoKH return VK_SUCCESS; } +uint64_t swapchain::get_modifier() +{ + return 0; +} + VkResult swapchain::allocate_and_bind_swapchain_image(VkImageCreateInfo image_create, swapchain_image &image) { UNUSED(image_create); diff --git a/wsi/headless/swapchain.hpp b/wsi/headless/swapchain.hpp index fdfe0a6..07c8bda 100644 --- a/wsi/headless/swapchain.hpp +++ b/wsi/headless/swapchain.hpp @@ -112,6 +112,8 @@ protected: VkResult image_wait_present(swapchain_image &image, uint64_t timeout) override; + uint64_t get_modifier() override; + /** * @brief Bind image to a swapchain * diff --git a/wsi/swapchain_base.hpp b/wsi/swapchain_base.hpp index 6c72347..26483f3 100644 --- a/wsi/swapchain_base.hpp +++ b/wsi/swapchain_base.hpp @@ -252,6 +252,15 @@ public: virtual VkResult bind_swapchain_image(VkDevice &device, const VkBindImageMemoryInfo *bind_image_mem_info, const VkBindImageMemorySwapchainInfoKHR *bind_sc_info) = 0; + /** + * @brief Get the DRM modifier of all swapchain images. + * + * Retrieves the DRM modifier used to create swapchain images. + * + * @return The DRM modifier used for the images. + */ + virtual uint64_t get_modifier() = 0; + /** * @brief Get image's present semaphore * diff --git a/wsi/wayland/swapchain.cpp b/wsi/wayland/swapchain.cpp index 3b9ebec..ca04ff6 100644 --- a/wsi/wayland/swapchain.cpp +++ b/wsi/wayland/swapchain.cpp @@ -464,6 +464,11 @@ VkResult swapchain::allocate_image(wayland_image_data *image_data) return VK_SUCCESS; } +uint64_t swapchain::get_modifier() +{ + return m_image_creation_parameters.m_allocated_format.modifier; +} + VkResult swapchain::create_wl_buffer(const VkImageCreateInfo &image_create_info, swapchain_image &image, wayland_image_data *image_data) { diff --git a/wsi/wayland/swapchain.hpp b/wsi/wayland/swapchain.hpp index 1297c72..95b9ff2 100644 --- a/wsi/wayland/swapchain.hpp +++ b/wsi/wayland/swapchain.hpp @@ -183,6 +183,8 @@ protected: VkResult bind_swapchain_image(VkDevice &device, const VkBindImageMemoryInfo *bind_image_mem_info, const VkBindImageMemorySwapchainInfoKHR *bind_sc_info) override; + uint64_t get_modifier() override; + /** * @brief Get backend specific image create info extensions. *