diff --git a/README.md b/README.md index fba34ce..f1dc805 100644 --- a/README.md +++ b/README.md @@ -1,70 +1,11 @@ # lsfg-vk-flake -Nix flake for using [Lossless Scaling's frame generation on Linux](https://github.com/PancakeTAS/lsfg-vk) +WIP! Nix flake to build the library for using Lossless Scaling's frame generation on Linux ->[!IMPORTANT] -> You need to have Lossless Scaling installed on Steam! -> In case it is not installed on the default Steam drive, you may want to consider setting the correct path in the lsfg-vk config. +current state: builds and seems to be functional -## Installation -### System-wide (NixOS module) -This approach will install an implicit layer to ``/etc/vulkan/implicit_layer.d/`` +## manual install +1. build the library with ``nix build`` +2. copy library and vulkan layer config to your ~/.local: ``cp -r result/* ~/.local/`` (check contents of result first!) +3. have lossless scaling installed on Steam or manually reference the DLL file using LSFG_DLL_PATH -Add this to your flake inputs, output function and modules list: -```nix -inputs = { - ... - lsfg-vk-flake.url = "github:pabloaul/lsfg-vk-flake/main"; - lsfg-vk-flake.inputs.nixpkgs.follows = "nixpkgs"; -} - -outputs = {nixpkgs, lsfg-vk-flake, ...}: { - - nixosConfigurations.hostname = nixpkgs.lib.nixosSystem { - ... - modules = [ - ... - lsfg-vk-flake.nixosModules.default - ]; - }; -} -``` - -And then enable this in your system config: -```nix -services.lsfg-vk = { - enable = true; - ui.enable = true; # installs gui for configuring lsfg-vk -}; -``` - -### User install (manual) -1. Build the library: - ```bash - nix build - ``` -2. Create the following path in case it does not exist: - ```bash - mkdir -p $HOME/.local/share/vulkan/implicit_layer.d - ``` -3. Symlink the build results to your $HOME/.local/ - ```bash - cp -ifrsv "$(readlink -f ./result)"/* $HOME/.local/ - ``` - -## Usage -Run a Vulkan application with the environment variable ``ENABLE_LSFG=1`` set. - -Example: -```bash -ENABLE_LSFG=1 vkcube -``` - -To confirm that it is working, look for output like this in the terminal: lsfg-vk(...): ... - -You can also enable it per game on Steam by adding this to the launch options: -``` -ENABLE_LSFG=1 %COMMAND% -``` - ->[!NOTE] -> If the environment variable is set but the program doesn't show any lsfg-vk output, you may need to add the application to your lsfg-vk configuration file at `~/.config/lsfg-vk/config.toml`. Read more about it in the [Wiki](https://github.com/PancakeTAS/lsfg-vk/wiki/Configuring-lsfg-vk) \ No newline at end of file +example usage command: ``LD_PRELOAD=~/.local/lib/liblsfg-vk.so LSFG_DLL_PATH=/Lossless.dll ENABLE_LSFG=1 vkcube`` diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..8c15c88 --- /dev/null +++ b/default.nix @@ -0,0 +1,78 @@ +{ lib +, fetchFromGitHub +, replaceVars +, cmake +, meson +, ninja +, SDL2 +, glslang +, vulkan-headers +, vulkan-loader +, pkg-config +, llvmPackages +, python3 +}: let + + peparse-git = fetchFromGitHub { + owner = "trailofbits"; + repo = "pe-parse"; + rev = "v2.1.1"; + hash = "sha256-WuG/OmzrXoH5O7+sSIdUVZP0aS63nuJwHgQfn12Q5xk="; + fetchSubmodules = true; + }; + + dxvk-git = fetchFromGitHub { + owner = "doitsujin"; + repo = "dxvk"; + rev = "v2.6.2"; + hash = "sha256-nZEi9WYhpI0WaeguoZMV4nt+nfaErvgz5RNDyyZYCJA="; + fetchSubmodules = true; + }; + +in llvmPackages.stdenv.mkDerivation { + pname = "lsfg-vk"; + version = "0.0.31"; + + src = fetchFromGitHub { + owner = "PancakeTAS"; + repo = "lsfg-vk"; + rev = "3ec418fd0f802f245bc31511d33c94a25d045ae8"; + hash = "sha256-xMRrqKaqKxzOjEFcLas6nRgvIpaZ94ca9BZemEPsIbU="; + }; + + # we need to unvendor dxvk and pe-parse which would normally be downloaded from git during buildtime in the cmakefiles + patches = [ + (replaceVars ./nix-cmake.patch { + inherit dxvk-git peparse-git python3; + }) + ]; + + cmakeFlags = [ + "-DCMAKE_BUILD_TYPE=Release" + ]; + + nativeBuildInputs = [ + # clang-tools needs to come before clang so it can locate Vulkan headers correctly + llvmPackages.clang-tools + llvmPackages.clang + llvmPackages.libllvm # needed for release builds + cmake + meson + ninja + pkg-config + glslang + python3 + ]; + + buildInputs = [ + SDL2 + vulkan-headers + vulkan-loader + ]; + + meta = with lib; { + homepage = "https://github.com/PancakeTAS/lsfg-vk/"; + license = licenses.mit; + platforms = platforms.linux; + }; +} diff --git a/flake.lock b/flake.lock index 83fcd4c..a63de06 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1756266583, - "narHash": "sha256-cr748nSmpfvnhqSXPiCfUPxRz2FJnvf/RjJGvFfaCsM=", + "lastModified": 1751792365, + "narHash": "sha256-J1kI6oAj25IG4EdVlg2hQz8NZTBNYvIS0l4wpr9KcUo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "8a6d5427d99ec71c64f0b93d45778c889005d9c2", + "rev": "1fd8bada0b6117e6c7eb54aad5813023eed37ccb", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 99e7737..7e14bb7 100644 --- a/flake.nix +++ b/flake.nix @@ -1,17 +1,10 @@ { inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - outputs = { nixpkgs, ... }: - let - forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ]; - in - { - packages = forAllSystems (system: { - default = nixpkgs.legacyPackages.${system}.callPackage ./lsfg-vk.nix { }; - lsfg-vk = nixpkgs.legacyPackages.${system}.callPackage ./lsfg-vk.nix { }; - lsfg-vk-ui = nixpkgs.legacyPackages.${system}.callPackage ./lsfg-vk-ui.nix { }; - }); - - nixosModules.default = import ./module.nix; + outputs = { nixpkgs, ... }: let + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; + in { + packages.${system}.default = pkgs.callPackage ./default.nix {}; }; } diff --git a/lsfg-vk-ui.nix b/lsfg-vk-ui.nix deleted file mode 100644 index 700eb7a..0000000 --- a/lsfg-vk-ui.nix +++ /dev/null @@ -1,54 +0,0 @@ -{ - lib, - fetchFromGitHub, - rustPlatform, - pkg-config, - glib, - pango, - gdk-pixbuf, - gtk4, - libadwaita, -}: - -rustPlatform.buildRustPackage rec { - pname = "lsfg-vk-ui"; - version = "1.0.0"; - - src = fetchFromGitHub { - owner = "PancakeTAS"; - repo = "lsfg-vk"; - tag = "v${version}"; - hash = "sha256-nIyVOil/gHC+5a+sH3vMlcqVhixjJaGWqXbyoh2Nqyw="; - }; - - cargoHash = "sha256-hIQRS/egIDU5Vu/1KWHtpt4S26h+9GadVr+lBAG2LDg="; - - sourceRoot = "source/ui"; - - nativeBuildInputs = [ - pkg-config - glib - ]; - - buildInputs = [ - pango - gdk-pixbuf - gtk4 - libadwaita - ]; - - postInstall = '' - install -Dm444 $src/ui/rsc/gay.pancake.lsfg-vk-ui.desktop $out/share/applications/gay.pancake.lsfg-vk-ui.desktop - install -Dm444 $src/ui/rsc/icon.png $out/share/icons/hicolor/256x256/apps/gay.pancake.lsfg-vk-ui.png - ''; - - meta = { - description = "Graphical configuration interface for lsfg-vk"; - homepage = "https://github.com/PancakeTAS/lsfg-vk/"; - changelog = "https://github.com/PancakeTAS/lsfg-vk/releases/tag/${src.tag}"; - license = lib.licenses.mit; - platforms = lib.platforms.linux; - maintainers = with lib.maintainers; [ pabloaul ]; - mainProgram = "lsfg-vk-ui"; - }; -} \ No newline at end of file diff --git a/lsfg-vk.nix b/lsfg-vk.nix deleted file mode 100644 index 63e494c..0000000 --- a/lsfg-vk.nix +++ /dev/null @@ -1,44 +0,0 @@ -{ - lib, - fetchFromGitHub, - cmake, - vulkan-headers, - llvmPackages, -}: - -llvmPackages.stdenv.mkDerivation rec { - pname = "lsfg-vk"; - version = "1.0.0"; - - src = fetchFromGitHub { - owner = "PancakeTAS"; - repo = "lsfg-vk"; - tag = "v${version}"; - hash = "sha256-hWpuPH7mKbeMaLaRUwtlkNLy4lOnJEe+yd54L7y2kV0="; - fetchSubmodules = true; - }; - - postPatch = '' - substituteInPlace VkLayer_LS_frame_generation.json \ - --replace-fail "liblsfg-vk.so" "$out/lib/liblsfg-vk.so" - ''; - - nativeBuildInputs = [ - llvmPackages.clang-tools - llvmPackages.libllvm - cmake - ]; - - buildInputs = [ - vulkan-headers - ]; - - meta = { - description = "Vulkan layer for frame generation (Requires owning Lossless Scaling)"; - homepage = "https://github.com/PancakeTAS/lsfg-vk/"; - changelog = "https://github.com/PancakeTAS/lsfg-vk/releases/tag/${src.tag}"; - license = lib.licenses.mit; - platforms = lib.platforms.linux; - maintainers = with lib.maintainers; [ pabloaul ]; - }; -} \ No newline at end of file diff --git a/module.nix b/module.nix deleted file mode 100644 index f2fcaa6..0000000 --- a/module.nix +++ /dev/null @@ -1,69 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: -let - cfg = config.services.lsfg-vk; - lsfg-vk = pkgs.callPackage ./lsfg-vk.nix { }; - lsfg-vk-ui = pkgs.callPackage ./lsfg-vk-ui.nix { }; -in -{ - options = { - services.lsfg-vk = { - enable = lib.mkEnableOption "Lossless Scaling Frame Generation Vulkan layer"; - - ui.enable = lib.mkEnableOption "Enables a GUI for configuring lsfg-vk"; - - package = lib.mkOption { - type = lib.types.package; - description = "The lsfg-vk package to use"; - default = lsfg-vk; - }; - - losslessDLLFile = lib.mkOption { - type = with lib.types; nullOr str; - default = null; - example = "/home/user/games/Lossless Scaling/Lossless.dll"; - description = '' - Sets the LSFG_DLL_PATH environment variable. - Required if Lossless Scaling isn't installed in a standard location - ''; - }; - - configFile = lib.mkOption { - type = with lib.types; nullOr str; - default = null; - example = "/home/user/.config/lsfg-vk/conf.toml"; - description = '' - Sets the LSFG_CONFIG environment variable. - Required if the lsfg-vk configuration file isn't stored at the standard location - ''; - }; - }; - }; - - config = lib.mkIf cfg.enable ( - lib.mkMerge [ - { - environment.systemPackages = [ cfg.package ]; - - # Installs the Vulkan implicit layer system-wide - environment.etc."vulkan/implicit_layer.d/VkLayer_LS_frame_generation.json".source = - "${cfg.package}/share/vulkan/implicit_layer.d/VkLayer_LS_frame_generation.json"; - } - (lib.mkIf cfg.ui.enable { - environment.systemPackages = [ lsfg-vk-ui ]; - }) - (lib.mkIf (cfg.losslessDLLFile != null) { - environment.sessionVariables.LSFG_DLL_PATH = - lib.warn "losslessDLLFile is deprecated and will only be used by lsfg-vk if LSFG_LEGACY is set." - cfg.losslessDLLFile; - }) - (lib.mkIf (cfg.configFile != null) { - environment.sessionVariables.LSFG_CONFIG = cfg.configFile; - }) - ] - ); -} diff --git a/nix-cmake.patch b/nix-cmake.patch new file mode 100644 index 0000000..7b9a452 --- /dev/null +++ b/nix-cmake.patch @@ -0,0 +1,50 @@ +diff --git a/cmake/FetchDXVK.cmake b/cmake/FetchDXVK.cmake +index f84de82..050b05b 100644 +--- a/cmake/FetchDXVK.cmake ++++ b/cmake/FetchDXVK.cmake +@@ -9,12 +9,13 @@ else() + endif() + + ExternalProject_Add(dxvk_git +- GIT_REPOSITORY "https://github.com/doitsujin/dxvk" +- GIT_TAG "v2.6.2" ++ URL file://@dxvk-git@ + UPDATE_DISCONNECTED true + USES_TERMINAL_CONFIGURE true + USES_TERMINAL_BUILD true + BUILD_IN_SOURCE true ++ PATCH_COMMAND ++ sed -i -e "s|^#!.*python3|#!@python3@/bin/python3|" /subprojects/libdisplay-info/tool/gen-search-table.py + CONFIGURE_COMMAND + sed -i s/private://g + src/dxvk/dxvk_shader.h && +@@ -51,10 +52,13 @@ target_link_directories(dxvk + INTERFACE ${SOURCE_DIR}/build/src/dxgi + INTERFACE ${SOURCE_DIR}/build/src/d3d11 + INTERFACE ${SOURCE_DIR}/build/src/spirv +- INTERFACE ${SOURCE_DIR}/build/src/util) ++ INTERFACE ${SOURCE_DIR}/build/src/util ++ INTERFACE ${SOURCE_DIR}/build/src/wsi ++ INTERFACE ${SOURCE_DIR}/build/src/vulkan ++ INTERFACE ${SOURCE_DIR}/build/subprojects/libdisplay-info) + target_include_directories(dxvk SYSTEM + INTERFACE ${SOURCE_DIR}/build-native/include/dxvk + INTERFACE ${SOURCE_DIR}/src + INTERFACE ${SOURCE_DIR}/include/spirv/include) + target_link_libraries(dxvk INTERFACE +- -Wl,--start-group dxgi d3d11 util ldxvk dxbc spirv -Wl,--end-group) ++ -Wl,--start-group dxgi d3d11 util ldxvk dxbc spirv wsi vkcommon display-info -Wl,--end-group) +diff --git a/cmake/FetchPeParse.cmake b/cmake/FetchPeParse.cmake +index df7879b..31a4b87 100644 +--- a/cmake/FetchPeParse.cmake ++++ b/cmake/FetchPeParse.cmake +@@ -1,8 +1,7 @@ + include(ExternalProject) + + ExternalProject_Add(peparse_git +- GIT_REPOSITORY "https://github.com/trailofbits/pe-parse" +- GIT_TAG "v2.1.1" ++ URL file://@peparse-git@ + UPDATE_DISCONNECTED true + USES_TERMINAL_CONFIGURE true + USES_TERMINAL_BUILD true