Merge 'Adding debug interface' into 'main'

See merge request mesa/vulkan-wsi-layer!209
This commit is contained in:
Rosen Zhelev 2025-11-04 12:20:24 +00:00
commit bb8770f80b
11 changed files with 117 additions and 0 deletions

View file

@ -52,6 +52,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden) set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
if(NOT DEFINED VULKAN_CXX_INCLUDE) if(NOT DEFINED VULKAN_CXX_INCLUDE)
set(VULKAN_CXX_INCLUDE ${VULKAN_PKG_CONFIG_INCLUDEDIR}) set(VULKAN_CXX_INCLUDE ${VULKAN_PKG_CONFIG_INCLUDEDIR})
@ -338,6 +339,10 @@ else()
add_definitions("-DVULKAN_WSI_LAYER_EXPERIMENTAL=0") add_definitions("-DVULKAN_WSI_LAYER_EXPERIMENTAL=0")
endif() 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_compile_definitions(${PROJECT_NAME} PRIVATE ${WSI_DEFINES})
target_include_directories(${PROJECT_NAME} PRIVATE target_include_directories(${PROJECT_NAME} PRIVATE
${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${VULKAN_CXX_INCLUDE}) ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${VULKAN_CXX_INCLUDE})

View file

@ -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 In order to enable this feature `-DENABLE_INSTRUMENTATION=1` option can
be passed at build time. 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 ## Installation
Copy the shared library `libVkLayer_window_system_integration.so` and JSON Copy the shared library `libVkLayer_window_system_integration.so` and JSON

33
util/debug.cpp Normal file
View file

@ -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 <wsi/swapchain_base.hpp>
void vk_wsi_layer_debug_get_sc_image_drm_mod(VkSwapchainKHR swapchain, uint64_t *modifier)
{
assert(swapchain != VK_NULL_HANDLE);
auto *sc = reinterpret_cast<wsi::swapchain_base *>(swapchain);
*modifier = sc->get_modifier();
}

39
util/debug.hpp Normal file
View file

@ -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 <vulkan/vulkan.h>
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);
}

View file

@ -74,6 +74,11 @@ static void page_flip_event(int fd, unsigned int sequence, unsigned int tv_sec,
*done = true; *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) 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); auto compression_control = wsi_ext_image_compression_control::create(device, swapchain_create_info);

View file

@ -125,6 +125,8 @@ protected:
const VkSwapchainCreateInfoKHR &swapchain_create_info, const VkSwapchainCreateInfoKHR &swapchain_create_info,
util::vector<util::unique_ptr<swapchain_image_create_info_extension>> *extensions) override; util::vector<util::unique_ptr<swapchain_image_create_info_extension>> *extensions) override;
uint64_t get_modifier() override;
private: private:
VkResult allocate_image(display_image_data *image_data); VkResult allocate_image(display_image_data *image_data);

View file

@ -142,6 +142,11 @@ VkResult swapchain::init_platform(VkDevice device, const VkSwapchainCreateInfoKH
return VK_SUCCESS; return VK_SUCCESS;
} }
uint64_t swapchain::get_modifier()
{
return 0;
}
VkResult swapchain::allocate_and_bind_swapchain_image(VkImageCreateInfo image_create, swapchain_image &image) VkResult swapchain::allocate_and_bind_swapchain_image(VkImageCreateInfo image_create, swapchain_image &image)
{ {
UNUSED(image_create); UNUSED(image_create);

View file

@ -112,6 +112,8 @@ protected:
VkResult image_wait_present(swapchain_image &image, uint64_t timeout) override; VkResult image_wait_present(swapchain_image &image, uint64_t timeout) override;
uint64_t get_modifier() override;
/** /**
* @brief Bind image to a swapchain * @brief Bind image to a swapchain
* *

View file

@ -252,6 +252,15 @@ public:
virtual VkResult bind_swapchain_image(VkDevice &device, const VkBindImageMemoryInfo *bind_image_mem_info, virtual VkResult bind_swapchain_image(VkDevice &device, const VkBindImageMemoryInfo *bind_image_mem_info,
const VkBindImageMemorySwapchainInfoKHR *bind_sc_info) = 0; 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 * @brief Get image's present semaphore
* *

View file

@ -464,6 +464,11 @@ VkResult swapchain::allocate_image(wayland_image_data *image_data)
return VK_SUCCESS; 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, VkResult swapchain::create_wl_buffer(const VkImageCreateInfo &image_create_info, swapchain_image &image,
wayland_image_data *image_data) wayland_image_data *image_data)
{ {

View file

@ -183,6 +183,8 @@ protected:
VkResult bind_swapchain_image(VkDevice &device, const VkBindImageMemoryInfo *bind_image_mem_info, VkResult bind_swapchain_image(VkDevice &device, const VkBindImageMemoryInfo *bind_image_mem_info,
const VkBindImageMemorySwapchainInfoKHR *bind_sc_info) override; const VkBindImageMemorySwapchainInfoKHR *bind_sc_info) override;
uint64_t get_modifier() override;
/** /**
* @brief Get backend specific image create info extensions. * @brief Get backend specific image create info extensions.
* *