diff --git a/CMake/compiler_linux.cmake b/CMake/compiler_linux.cmake index 904d96a9..ab8f0e95 100644 --- a/CMake/compiler_linux.cmake +++ b/CMake/compiler_linux.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Lukasz Stalmirski +# Copyright (c) 2024-2026 Lukasz Stalmirski # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -20,9 +20,18 @@ cmake_minimum_required (VERSION 3.8...3.31) +string (TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_TYPE) + +# Include debug information in debug builds. +if ("${BUILD_TYPE}" STREQUAL "debug" OR + "${BUILD_TYPE}" STREQUAL "relwithdebinfo") + add_compile_options (-g) +endif () + # Generate Position Independent Code (PIC) since we're targeting a shared library. add_compile_options (-fPIC) # Export symbols explicitly. set (CMAKE_CXX_VISIBILITY_PRESET hidden) set (CMAKE_VISIBILITY_INLINES_HIDDEN 1) + diff --git a/CMake/platform_linux.cmake b/CMake/platform_linux.cmake index d8ff7da1..25852a15 100644 --- a/CMake/platform_linux.cmake +++ b/CMake/platform_linux.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2025 Lukasz Stalmirski +# Copyright (c) 2023-2026 Lukasz Stalmirski # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -23,6 +23,10 @@ cmake_minimum_required (VERSION 3.8...3.31) find_package (X11) if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16.0) + # Suppress CMake version warnings in ECM by requiring at least 3.16+ + # once we checked that it is indeed 3.16+. + cmake_minimum_required (VERSION 3.16...3.31) + # ECM is required on Linux to find Wayland and XCB. find_package (ECM NO_MODULE) if (ECM_FOUND) diff --git a/Docs/getting_started/building.rst b/Docs/getting_started/building.rst index 2a522cad..8facddf2 100644 --- a/Docs/getting_started/building.rst +++ b/Docs/getting_started/building.rst @@ -53,20 +53,20 @@ The layer uses CMake build management tool, so building it is straightforward. 1. Clone the repository. - .. code:: + .. code:: bash git clone --recursive https://github.com/lstalmir/VulkanProfiler cd VulkanProfiler 2. Install Python packages. - .. code:: + .. code:: bash python3 -m pip install -r VkLayer_profiler_layer/scripts/requirements.txt 3. Generate the project files / makefiles in the build directory. - .. code:: + .. code:: bash mkdir cmake_build cd cmake_build @@ -74,9 +74,9 @@ The layer uses CMake build management tool, so building it is straightforward. 4. Build the layer. - .. code:: + .. code:: bash - cmake --build . --config Release + cmake --build . --config Release -j Building with Visual Studio --------------------------- @@ -93,7 +93,7 @@ Unix makefiles is the default CMake generator on Linux systems. Build directory Once generated, the project can be built by running make: -.. code:: +.. code:: bash make all @@ -102,11 +102,15 @@ Packaging CMake install step can be used to collect all files into a single directory: -.. code:: +.. code:: bash cmake --install . --config Release --prefix -The layer files will be placed in ``/bin`` on Windows, ``/lib`` on Linux, or in ``/lib/`` on multiarch Linux distributions (e.g., ``/lib/x86_64-linux-gnu``). +The layer libraries will be placed in ``/bin`` on Windows, ``/lib`` on Linux, or in ``/lib/`` on multiarch Linux distributions (e.g., ``/lib/x86_64-linux-gnu``). + +On Windows, the JSON manifest file is located next to the DLL. On Linux, it is placed in ``/share/vulkan/explicit_layer.d`` directory. + +On Linux, the layer can be also installed directly to the current system by providing ``/usr/local`` or ``/usr`` prefix. Building documentation ---------------------- @@ -121,6 +125,6 @@ The packages required for building are listed in Docs/requirements.txt: With the packages installed, sphinx-build tool can be used: -.. code:: +.. code:: bash sphinx-build -M html ./Docs ./docs_build diff --git a/Docs/getting_started/installation.rst b/Docs/getting_started/installation.rst index 29d6dd3b..f0f651f0 100644 --- a/Docs/getting_started/installation.rst +++ b/Docs/getting_started/installation.rst @@ -7,7 +7,13 @@ Once downloaded or built, the dynamic-link library with the layer must be instal .. note:: - Installation of the layer can be avoided. To use the layer without installation set ``VK_LAYER_PATH`` environment variable to the directory containing layer files. + Installation of the layer can be avoided. To use the layer without installation set ``VK_LAYER_PATH`` environment variable to the directory containing the JSON file. + + Additionally, when using this approach on Linux systems, ``LD_LIBRARY_PATH`` has to contain path to the .so files: + + .. code:: bash + + export LD_LIBRARY_PATH=/home/user/vulkan-profiler/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH Windows ------- @@ -26,11 +32,17 @@ Linux The following instructions have been prepared for Debian-based distributions. Locations of Vulkan layers may be different on other distros. -Vulkan layers on Linux are stored in predefined directories. To install the layer, simply copy the .so and .json files from the package to one of those directories. +Vulkan layers on Linux are stored in predefined directories. To install the layer, copy the JSON manifest file to one of the directories listed below: - $HOME/.local/share/vulkan/explicit_layer.d - /usr/local/share/vulkan/explicit_layer.d - /usr/share/vulkan/explicit_layer.d - /etc/vulkan/explicit_layer.d +Then, copy all .so files from the package (from "lib" directory) to one of the system library locations: + +- /usr/local/lib +- /usr/lib +- /lib + Apart from the libVkLayer_profiler_layer.so that is the Vulkan layer library, the layer also requires libigdmd to support Intel performance counters on Linux. This library can be found either in the package, next to libVkLayer_profiler_layer.so, or in "/External/metrics-discovery/dump/linux64//metrics_discovery" directory when building the layer from source. diff --git a/README.md b/README.md index 5aefda7a..b85c369d 100644 --- a/README.md +++ b/README.md @@ -39,21 +39,21 @@ Following packages are required for building on Debian-based systems: To build the layer create "cmake_build" folder in the project root directory and run following command from it: ``` -cmake .. && make all +cmake .. -DCMAKE_BUILD_TYPE=Release && make all -j ``` -Then, to put all required files in a single directory, run install step: +Then, install the layer: ``` -cmake --install . --prefix +sudo cmake --install . --prefix /usr/local/ ``` -To install the layer copy `libVkLayer_profiler_layer.so` and `VkLayer_profiler_layer.json` files to `~/.local/share/vulkan/explicit_layer.d` directory. +This command will copy all required libraries to `/usr/local/lib` directory and the JSON manifest file to `/usr/local/share/vulkan/explicit_layer.d` directory. -To support Intel performance counters on Linux the layer requires `libigdmd` to be present in the same directory. The library is built as part of the project and its binaries are located in `/External/metrics-discovery/dump/linux64//metrics_discovery`. These files are also copied during install step into `/lib/` directory. +To support Intel performance counters on Linux the layer requires `libigdmd`. The library is built as part of the project and its binaries are located in `/External/metrics-discovery/dump/linux64//metrics_discovery`. These files are also copied during install step into `/lib/` directory. > [!NOTE] -> On multiarch Linux distributions all the libraries and JSON files will be placed in `/lib//`, e.g. `install/lib/x86_64-linux-gnu/`. +> On multiarch Linux distributions all the libraries will be placed in `/lib//`, e.g. `/usr/local/lib/x86_64-linux-gnu/`. ### Notes Installation of the layer can be avoided. To use the layer without installation set VK_LAYER_PATH environment variable to the directory containing layer files. diff --git a/VkLayer_profiler_layer/CMakeLists.txt b/VkLayer_profiler_layer/CMakeLists.txt index 163150c6..ba2e72e7 100644 --- a/VkLayer_profiler_layer/CMakeLists.txt +++ b/VkLayer_profiler_layer/CMakeLists.txt @@ -76,19 +76,6 @@ project (${PROFILER_LAYER_PROJECTNAME}) message ("-- Profiler version: ${PROFILER_LAYER_VER_MAJOR}.${PROFILER_LAYER_VER_MINOR}.${PROFILER_LAYER_VER_BUILD}.${PROFILER_LAYER_VER_PATCH}") message ("-- Vulkan version: ${PROFILER_LAYER_API_VERSION}") -# Generate layer manifest file -set (json - "${CMAKE_CURRENT_BINARY_DIR}/${PROFILER_LAYER_PROJECTNAME}.json" - ) - -if (WIN32) - # WA: Windows uses backslash as directory separator, which needs to be - # escaped twice (once here and once in the json, thus 4 backslashes) - set (THIS_DIR ".\\\\") -else () - set (THIS_DIR "./") -endif () - function (configure_and_generate_file IN_FILE OUT_FILE) get_filename_component (IN_FILE_NAME "${IN_FILE}" NAME) set (CONFIGURED_FILE "${CMAKE_CURRENT_BINARY_DIR}/${IN_FILE_NAME}.configured") @@ -103,17 +90,41 @@ function (configure_and_generate_file IN_FILE OUT_FILE) INPUT "${CONFIGURED_FILE}") endfunction () +# Generate layer manifest file +set (PROFILER_LAYER_JSON_FILENAME "${PROFILER_LAYER_PROJECTNAME}.json") +set (PROFILER_LAYER_JSON_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROFILER_LAYER_JSON_FILENAME}") +set (PROFILER_LAYER_JSON_INSTALL_FILE "${PROFILER_LAYER_JSON_FILE}") + +if (WIN32) + # WA: Windows uses backslash as directory separator, which needs to be + # escaped twice (once here and once in the json, thus 4 backslashes) + set (PROFILER_LAYER_JSON_DLL_PREFIX ".\\\\") +else () + set (PROFILER_LAYER_JSON_DLL_PREFIX "./") +endif () + configure_and_generate_file ( - "${CMAKE_CURRENT_SOURCE_DIR}/${PROFILER_LAYER_PROJECTNAME}.json.in" - "${json}") + "${CMAKE_CURRENT_SOURCE_DIR}/${PROFILER_LAYER_JSON_FILENAME}.in" + "${PROFILER_LAYER_JSON_FILE}") + +if (NOT WIN32) + # On Linux the layer library is installed in /lib directory and the manifest + # is placed in /shared/vulkan/explicit_layers.d. + # Remove the local directory prefix to use system library load paths. + set (PROFILER_LAYER_JSON_DLL_PREFIX "") + set (PROFILER_LAYER_JSON_INSTALL_FILE "${PROFILER_LAYER_JSON_FILE}.install") + configure_and_generate_file ( + "${CMAKE_CURRENT_SOURCE_DIR}/${PROFILER_LAYER_JSON_FILENAME}.in" + "${PROFILER_LAYER_JSON_INSTALL_FILE}") +endif () add_custom_command ( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/vk_layer_config.h" COMMAND "${Python3_EXECUTABLE}" "${PROFILER_SCRIPTS_DIR}/gen_config.py" - "${json}" + "${PROFILER_LAYER_JSON_FILE}" --output "${CMAKE_CURRENT_BINARY_DIR}/vk_layer_config.h" - DEPENDS "${json}" + DEPENDS "${PROFILER_LAYER_JSON_FILE}" DEPENDS "${PROFILER_SCRIPTS_DIR}/gen_config.py") list (APPEND PROFILER_CODEGEN_FILES "${CMAKE_CURRENT_BINARY_DIR}/vk_layer_config.h") @@ -369,7 +380,8 @@ target_link_libraries (${PROFILER_LAYER_PROJECTNAME} add_custom_command (TARGET ${PROFILER_LAYER_PROJECTNAME} POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy - "${json}" "$/${PROFILER_LAYER_PROJECTNAME}.json") + "${PROFILER_LAYER_JSON_FILE}" + "$/${PROFILER_LAYER_JSON_FILENAME}") # Set include path target_include_directories (${PROFILER_LAYER_PROJECTNAME}_lib @@ -384,11 +396,24 @@ install (TARGETS ${PROFILER_LAYER_PROJECTNAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") -install (FILES "${PROFILER_LICENSES_FILE}" DESTINATION .) - -# Copy JSON to the path where DLL/SO is installed if (WIN32) -install (FILES ${json} DESTINATION "${CMAKE_INSTALL_BINDIR}") + # Copy JSON to the path where the DLL is installed. + install (FILES "${PROFILER_LAYER_JSON_INSTALL_FILE}" + DESTINATION "${CMAKE_INSTALL_BINDIR}" + RENAME "${PROFILER_LAYER_JSON_FILENAME}") + + # Include a file with all third-party software licenses. + install (FILES "${PROFILER_LICENSES_FILE}" + DESTINATION . + RENAME "${PROFILER_LAYER_PROJECTNAME}_licenses.rst") else () -install (FILES ${json} DESTINATION "${CMAKE_INSTALL_LIBDIR}") + # Copy JSON to shared directory. + install (FILES "${PROFILER_LAYER_JSON_INSTALL_FILE}" + DESTINATION "${CMAKE_INSTALL_DATADIR}/vulkan/explicit_layer.d" + RENAME "${PROFILER_LAYER_JSON_FILENAME}") + + # Include a file with all third-party software licenses. + install (FILES "${PROFILER_LICENSES_FILE}" + DESTINATION "${CMAKE_INSTALL_DATADIR}/vulkan/explicit_layer.d" + RENAME "${PROFILER_LAYER_PROJECTNAME}_licenses.rst") endif () diff --git a/VkLayer_profiler_layer/VkLayer_profiler_layer.json.in b/VkLayer_profiler_layer/VkLayer_profiler_layer.json.in index c6eb3e1e..374e1b7e 100644 --- a/VkLayer_profiler_layer/VkLayer_profiler_layer.json.in +++ b/VkLayer_profiler_layer/VkLayer_profiler_layer.json.in @@ -3,7 +3,7 @@ "layer": { "name": "@PROFILER_LAYER_NAME@", "type": "GLOBAL", - "library_path": "@THIS_DIR@$", + "library_path": "@PROFILER_LAYER_JSON_DLL_PREFIX@$", "api_version": "@PROFILER_LAYER_API_VERSION@", "implementation_version": "@PROFILER_LAYER_VER_BUILD@", "description": "@PROFILER_LAYER_FILEDESCRIPTION@", diff --git a/VkLayer_profiler_layer/profiler_tests/CMakeLists.txt b/VkLayer_profiler_layer/profiler_tests/CMakeLists.txt index 3903da07..44368519 100644 --- a/VkLayer_profiler_layer/profiler_tests/CMakeLists.txt +++ b/VkLayer_profiler_layer/profiler_tests/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2023 Lukasz Stalmirski +# Copyright (c) 2019-2026 Lukasz Stalmirski # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -64,5 +64,8 @@ if (BUILD_TESTS) PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" ) - install (TARGETS profiler_tests) + install (TARGETS profiler_tests + COMPONENT Tests + EXCLUDE_FROM_ALL + ) endif (BUILD_TESTS)