Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CMake/compiler_linux.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

6 changes: 5 additions & 1 deletion CMake/platform_linux.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
22 changes: 13 additions & 9 deletions Docs/getting_started/building.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,30 @@ 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
cmake .. -DCMAKE_BUILD_TYPE=Release

4. Build the layer.

.. code::
.. code:: bash

cmake --build . --config Release
cmake --build . --config Release -j

Building with Visual Studio
---------------------------
Expand All @@ -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

Expand 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 <install_dir>

The layer files will be placed in ``<install_dir>/bin`` on Windows, ``<install_dir>/lib`` on Linux, or in ``<install_dir>/lib/<arch>`` on multiarch Linux distributions (e.g., ``<install_dir>/lib/x86_64-linux-gnu``).
The layer libraries will be placed in ``<install_dir>/bin`` on Windows, ``<install_dir>/lib`` on Linux, or in ``<install_dir>/lib/<arch>`` on multiarch Linux distributions (e.g., ``<install_dir>/lib/x86_64-linux-gnu``).

On Windows, the JSON manifest file is located next to the DLL. On Linux, it is placed in ``<install_dir>/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
----------------------
Expand All @@ -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
16 changes: 14 additions & 2 deletions Docs/getting_started/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand All @@ -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 "<REPOSITORY_DIR>/External/metrics-discovery/dump/linux64/<CONFIG>/metrics_discovery" directory when building the layer from source.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <INSTALL_DIR>
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 `<REPOSITORY_ROOT_DIR>/External/metrics-discovery/dump/linux64/<CONFIG>/metrics_discovery`. These files are also copied during install step into `<INSTALL_DIR>/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 `<REPOSITORY_ROOT_DIR>/External/metrics-discovery/dump/linux64/<CONFIG>/metrics_discovery`. These files are also copied during install step into `<INSTALL_DIR>/lib/` directory.

> [!NOTE]
> On multiarch Linux distributions all the libraries and JSON files will be placed in `<INSTALL_DIR>/lib/<ARCH>/`, e.g. `install/lib/x86_64-linux-gnu/`.
> On multiarch Linux distributions all the libraries will be placed in `<INSTALL_DIR>/lib/<ARCH>/`, 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.
Expand Down
71 changes: 48 additions & 23 deletions VkLayer_profiler_layer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 <prefix>/lib directory and the manifest
# is placed in <prefix>/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")

Expand Down Expand Up @@ -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}" "$<TARGET_FILE_DIR:${PROFILER_LAYER_PROJECTNAME}>/${PROFILER_LAYER_PROJECTNAME}.json")
"${PROFILER_LAYER_JSON_FILE}"
"$<TARGET_FILE_DIR:${PROFILER_LAYER_PROJECTNAME}>/${PROFILER_LAYER_JSON_FILENAME}")

# Set include path
target_include_directories (${PROFILER_LAYER_PROJECTNAME}_lib
Expand All @@ -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 ()
2 changes: 1 addition & 1 deletion VkLayer_profiler_layer/VkLayer_profiler_layer.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"layer": {
"name": "@PROFILER_LAYER_NAME@",
"type": "GLOBAL",
"library_path": "@THIS_DIR@$<TARGET_FILE_NAME:@PROFILER_LAYER_PROJECTNAME@>",
"library_path": "@PROFILER_LAYER_JSON_DLL_PREFIX@$<TARGET_FILE_NAME:@PROFILER_LAYER_PROJECTNAME@>",
"api_version": "@PROFILER_LAYER_API_VERSION@",
"implementation_version": "@PROFILER_LAYER_VER_BUILD@",
"description": "@PROFILER_LAYER_FILEDESCRIPTION@",
Expand Down
7 changes: 5 additions & 2 deletions VkLayer_profiler_layer/profiler_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Loading