From a6430cbe5462801505ef68caf08db3d6a8244b06 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Tue, 31 Mar 2026 18:20:20 +1100 Subject: Add 'make install' command via cmake, update README.md --- CMakeLists.txt | 30 ++++++++++----------- README.md | 66 ++++++++++------------------------------------- low_latency_layer.json | 21 --------------- low_latency_layer.json.in | 21 +++++++++++++++ 4 files changed, 48 insertions(+), 90 deletions(-) delete mode 100644 low_latency_layer.json create mode 100644 low_latency_layer.json.in diff --git a/CMakeLists.txt b/CMakeLists.txt index a82394d..bc11d7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.10) project(low_latency_layer - VERSION 0.01 + VERSION 0.02 LANGUAGES CXX ) @@ -22,22 +22,18 @@ target_link_libraries(${LIBRARY_NAME} ${Vulkan_LIBRARIES} ) -# Copy layer into out/ -set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/out") -add_custom_command(TARGET ${LIBRARY_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory "${OUTPUT_DIR}" +include(GNUInstallDirs) +# Prefix an absolute directory to our layer's json so the loader knows where the shared library is. +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/low_latency_layer.json.in" + "${CMAKE_CURRENT_BINARY_DIR}/low_latency_layer.json" + @ONLY ) - -add_custom_command(TARGET ${LIBRARY_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "$" - "${OUTPUT_DIR}/" +install(TARGETS ${LIBRARY_NAME} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) - -add_custom_command(TARGET ${LIBRARY_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${CMAKE_CURRENT_SOURCE_DIR}/low_latency_layer.json" - "${OUTPUT_DIR}/" +install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/low_latency_layer.json" + DESTINATION "${CMAKE_INSTALL_DATADIR}/vulkan/implicit_layer.d/" ) target_compile_options(${LIBRARY_NAME} PRIVATE @@ -58,6 +54,6 @@ target_compile_options(${LIBRARY_NAME} PRIVATE $<$>:-Wno-unused-variable -Wno-unused-but-set-variable> -Wundef - -Wconversion + -Wconversion -Wdouble-promotion -) \ No newline at end of file +) diff --git a/README.md b/README.md index c0c501f..b86cc87 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,18 @@ # low_latency_layer -A C++23 Vulkan layer that reduces click-to-photon latency via AMD's latency reduction technology. +A C++23 implicit Vulkan layer that reduces click-to-photon latency by implementing both AMD and NVIDIA's latency reduction technologies. -This layer was designed to maximise latency reduction without reducing FPS throughput. [Initial benchmarks are available here.](#benchmarks) +The layer allows AMD or Intel hardware to provide implementations for and switch between `VK_NV_low_latency2` and `VK_AMD_anti_lag` device extensions. This capability, coupled with work that forwards relevant calls in [dvxk-nvapi](https://github.com/jp7677/dxvk-nvapi/), allows the use of these technologies despite the lack of a driver-level implementation. -# Features +The layer also eliminates a hardware support disparity as considerably more applications support NVIDIA's Reflex than AMD's Anti-Lag. -- **AMD Anti-Lag 2:** Greatly reduces latency by synchronising the GPU and CPU when input is collected. -- **AMD Anti-Lag 1:** Reduces latency by eliminating queueing using GPU and CPU timing data. +[Benchmarks are available here.](#benchmarks) # Planned -- Anti-Lag 2's optional framerate Limit. -- Anti-Lag 1 & DXVK: The asynchronous nature of DXVK means that Anti-Lag 1 will not function correctly (unlike Anti-Lag 2, which works!). -- Improvements to the Anti-Lag 1 algorithm for more aggressive latency reduction. -- Improvements to logging and statistics so that special hardware isn't needed to verify the layer is functioning correctly. -- Cross-platform builds (time domain adjustments required). +- Respect the provided framerate limit. +- Cross-platform builds (small amount of time domain work required). +- Improvements to logging and statistics. - HUD with latency information. # Dependencies @@ -24,7 +21,7 @@ This layer was designed to maximise latency reduction without reducing FPS throu - [Vulkan Headers](https://github.com/KhronosGroup/Vulkan-Headers): Vulkan header files and API registry. - [Vulkan Utility Libraries](https://github.com/KhronosGroup/Vulkan-Utility-Libraries): Library to share code across various Vulkan repositories. -# Building from Source +# Building from Source and Installation Clone this repo. @@ -33,61 +30,26 @@ Clone this repo. $ cd low_latency_layer ``` -Create an out-of-tree build directory (creatively we'll use 'build') and compile from source. +Create an out-of-tree build directory (creatively we'll use 'build') and install. > ⚠️ **WARNING:** You are likely going to have to install your distro's `vulkan-headers`, `vulkan-utility-libraries`, and possibly even `cmake` packages before proceeding. If you see an error here their absense is almost certainly the reason. ``` $ cmake -B build ./ $ cd ./build - $ make + $ sudo make install ``` -Provided nothing went horribly wrong you should find `libVkLayer_NJ3AHXAC_LowLatency.so` and `low_latency_layer.json` in the `build/out` directory. That's it! +To verify that the installation succeeded you can run this command. If it prints '1', you're good to go. -# Installation - -This layer interacts with the Vulkan Loader, which has to see the layer to inject it. [You can read about the many ways a layer can be discovered here](https://github.com/KhronosGroup/Vulkan-Loader/blob/main/docs/LoaderLayerInterface.md#layer-discovery). One way is to use the `VK_ADD_IMPLICIT_LAYER_PATH` env var to surgically add a location to where the loader looks. We're going to use this method. - -If you want to enable the layer globally and don't want to pollute your system with untracked files and shared libraries (recommended), you should append a line in your `/etc/environment` to point the loader to where you built the layer: - -``` - VK_ADD_IMPLICIT_LAYER_PATH="/the/prefix/to/your/cloned/repository/low_latency_layer/build/out/" -``` - -If you want to enable the layer only for a specific program on Steam you can just modify its launch options like so: ``` - VK_ADD_IMPLICIT_LAYER_PATH="/the/prefix/to/your/cloned/repository/low_latency_layer/build/out/" %command% + $ ENABLE_LOW_LATENCY_LAYER=1 vulkaninfo 2>/dev/null | grep -q VK_LAYER_NJ3AHXAC_LowLatency && echo 1 || echo 0 ``` -Keep in mind that if you use the first `/etc/environment` option, you might need to restart your session for it to take effect everywhere. - -# Anti-Lag 2 Usage - -Provided the loader has injected the layer and your GPU supports the extensions we need to function, the layer will provide the `VK_AMD_anti_lag` device extension. It's up to the application for what happens next. Typically you will see something about Anti-Lag in video settings - for example, in Counter Strike 2 you will see this: - -![cs2_settings](http://git.nj3.xyz/files/plain/low_latency_layer/cs2_enabled.png?h=main) - -It's difficult for humans to detect differences in input latency without special hardware. In GPU heavy scenarios, Anti-Lag 2 should eliminate the 'sluggish' mouse feeling that cannot be explained by poor FPS. The input latency that this layer targets is insidious in that it may only become apparent at certain points during gameplay. Specifically, this happens when the GPU has much more work than the CPU, allowing the CPU to _run ahead_ of the GPU. - -If you need convincing that the layer is doing something and don't have access to special hardware, you can simply look at your framerate. With Anti-Lag 2 enabled, you should see a very slight reduction in throughput. Alternatively, you might notice a slight reduction in GPU utilisation. - -# Anti-Lag 1 Usage - -For games that do not support Anti-Lag 2, we provide the ability to use Anti-Lag 1. Unlike Anti-Lag 2, the application does not need to be aware of - or have a working implementation of - the technology to function correctly. It's a bit less robust, and its performance is almost certainly worse than Anti-Lag 2, but it has the advantage of being universally applicable. - -> ⚠️ **WARNING:** Anti-Lag 1 is not functioning correctly with DXVK. Do not expect it to work outside of native Linux games. - -Anti-Lag 1 is not enabled by default. Instead, an environment variable toggle is provided. This must be set to exactly the string `"1"` - all other values are ignored. - -``` - LOW_LATENCY_LAYER_SLEEP_AFTER_PRESENT="1" -``` - -If Anti-Lag 1 is enabled alongside Anti-Lag 2, Anti-Lag 2 will take priority. - # Benchmarks +WIP - not updated for reflex merge + ## Counter-Strike 2 ![cs2](http://git.nj3.xyz/files/plain/low_latency_layer/cs2.png?h=main) diff --git a/low_latency_layer.json b/low_latency_layer.json deleted file mode 100644 index de04465..0000000 --- a/low_latency_layer.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "file_format_version": "1.0.0", - "layer": { - "name": "VK_LAYER_NJ3AHXAC_LowLatency", - "type": "GLOBAL", - "library_path": "./libVkLayer_NJ3AHXAC_LowLatency.so", - "api_version": "1.3.0", - "implementation_version": "1", - "description": "Input latency reduction layer", - "functions": { - "vkGetInstanceProcAddr": "LowLatency_GetInstanceProcAddr", - "vkGetDeviceProcAddr": "LowLatency_GetDeviceProcAddr" - }, - "enable_environment": { - "ENABLE_LOW_LATENCY_LAYER": "1" - }, - "disable_environment": { - "DISABLE_LOW_LATENCY_LAYER": "1" - } - } -} \ No newline at end of file diff --git a/low_latency_layer.json.in b/low_latency_layer.json.in new file mode 100644 index 0000000..d52a200 --- /dev/null +++ b/low_latency_layer.json.in @@ -0,0 +1,21 @@ +{ + "file_format_version": "1.0.0", + "layer": { + "name": "VK_LAYER_NJ3AHXAC_LowLatency", + "type": "GLOBAL", + "library_path": "@CMAKE_INSTALL_FULL_LIBDIR@/libVkLayer_NJ3AHXAC_LowLatency.so", + "api_version": "1.3.0", + "implementation_version": "2", + "description": "Input latency reduction layer", + "functions": { + "vkGetInstanceProcAddr": "LowLatency_GetInstanceProcAddr", + "vkGetDeviceProcAddr": "LowLatency_GetDeviceProcAddr" + }, + "enable_environment": { + "ENABLE_LOW_LATENCY_LAYER": "1" + }, + "disable_environment": { + "DISABLE_LOW_LATENCY_LAYER": "1" + } + } +} \ No newline at end of file -- cgit v1.2.3