From 5af4dc5d52a306272f4d4a97079aeef3888ae210 Mon Sep 17 00:00:00 2001 From: ChaosAttractor <46527539+LostAttractor@users.noreply.github.com> Date: Sat, 28 Jan 2023 23:46:56 +0800 Subject: [PATCH 1/3] Add the option of whether to install the opencl environment and whether to use amdvlk for amdgpu --- common/gpu/amd/default.nix | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/common/gpu/amd/default.nix b/common/gpu/amd/default.nix index 91ba0b7..e86bb01 100644 --- a/common/gpu/amd/default.nix +++ b/common/gpu/amd/default.nix @@ -6,11 +6,30 @@ ) // { default = true; }; + options.hardware.amdgpu.amdvlk = lib.mkEnableOption (lib.mdDoc + "use amdvlk drivers instead mesa radv drivers" + ) // { + default = true; + }; + options.hardware.amdgpu.opencl = lib.mkEnableOption (lib.mdDoc + "rocm opencl runtime (Install rocm-opencl-icd and rocm-opencl-runtime)" + ) // { + default = true; + }; config = lib.mkMerge [ { services.xserver.videoDrivers = lib.mkDefault [ "amdgpu" ]; - + + hardware.opengl = { + driSupport = lib.mkDefault true; + driSupport32Bit = lib.mkDefault true; + }; + } + (lib.mkIf config.hardware.amdgpu.loadInInitrd { + boot.initrd.kernelModules = [ "amdgpu" ]; + }) + (lib.mkIf config.hardware.amdgpu.amdvlk { hardware.opengl.extraPackages = with pkgs; [ rocm-opencl-icd rocm-opencl-runtime @@ -20,16 +39,14 @@ hardware.opengl.extraPackages32 = with pkgs; [ driversi686Linux.amdvlk ]; - - hardware.opengl = { - driSupport = lib.mkDefault true; - driSupport32Bit = lib.mkDefault true; - }; - + environment.variables.AMD_VULKAN_ICD = lib.mkDefault "RADV"; - } - (lib.mkIf config.hardware.amdgpu.loadInInitrd { - boot.initrd.kernelModules = [ "amdgpu" ]; + }) + (lib.mkIf config.hardware.amdgpu.opencl { + hardware.opengl.extraPackages = with pkgs; [ + rocm-opencl-icd + rocm-opencl-runtime + ]; }) ]; } From be60a34c1a6c3aa3e878fb5030e44c6d0f316af9 Mon Sep 17 00:00:00 2001 From: ChaosAttractor <46527539+LostAttractor@users.noreply.github.com> Date: Sat, 28 Jan 2023 23:49:25 +0800 Subject: [PATCH 2/3] 16ach6h: disable amdvlk and rocm-opencl for nvidia-only mode --- lenovo/legion/16ach6h/default.nix | 8 +++++++- lenovo/legion/16ach6h/nvidia/default.nix | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lenovo/legion/16ach6h/default.nix b/lenovo/legion/16ach6h/default.nix index 4041c09..523d9d0 100644 --- a/lenovo/legion/16ach6h/default.nix +++ b/lenovo/legion/16ach6h/default.nix @@ -7,6 +7,12 @@ # This specialisation is for the case where "DDG" (Dual-Direct GFX, A hardware feature that can enable in bios) is enabled, since the amd igpu is blocked at hardware level and the built-in display is directly connected to the dgpu, we no longer need the amdgpu and prime configuration. system.nixos.tags = [ "Dual-Direct-GFX-Mode" ]; services.xserver.videoDrivers = [ "nvidia" ]; # This will override services.xserver.videoDrivers = lib.mkDefault [ "amdgpu" "nvidia" ]; - hardware.nvidia.prime.offload.enable = false; + hardware = { + nvidia.prime.offload.enable = false; + amdgpu = { + amdvlk = false; + opencl = false; + }; + }; }; } \ No newline at end of file diff --git a/lenovo/legion/16ach6h/nvidia/default.nix b/lenovo/legion/16ach6h/nvidia/default.nix index e54fc20..85f7ee1 100644 --- a/lenovo/legion/16ach6h/nvidia/default.nix +++ b/lenovo/legion/16ach6h/nvidia/default.nix @@ -3,5 +3,11 @@ { imports = [ ../hybrid ]; services.xserver.videoDrivers = [ "nvidia" ]; # This will override services.xserver.videoDrivers = lib.mkDefault [ "amdgpu" "nvidia" ]; - hardware.nvidia.prime.offload.enable = false; + hardware = { + nvidia.prime.offload.enable = false; + amdgpu = { + amdvlk = false; + opencl = false; + }; + }; } \ No newline at end of file From 445db26b8864bf34c236f936a9330272f232cd51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Thu, 9 Feb 2023 09:04:15 +0000 Subject: [PATCH 3/3] Update lenovo/legion/16ach6h/nvidia/default.nix --- lenovo/legion/16ach6h/nvidia/default.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lenovo/legion/16ach6h/nvidia/default.nix b/lenovo/legion/16ach6h/nvidia/default.nix index 85f7ee1..31de5c1 100644 --- a/lenovo/legion/16ach6h/nvidia/default.nix +++ b/lenovo/legion/16ach6h/nvidia/default.nix @@ -3,6 +3,19 @@ { imports = [ ../hybrid ]; services.xserver.videoDrivers = [ "nvidia" ]; # This will override services.xserver.videoDrivers = lib.mkDefault [ "amdgpu" "nvidia" ]; + # When I play the game through proton, I found that in the case of Dual-Direct GFX + # enabled (dGPU disabled), proton will crash directly. But in the case of hybrid, + # the game runs fine with or without nvidia-offload After investigation, this is + # because when writing the specialization of Dual-Direct GFX, I did not completely + # remove all packages for amd igpu. I only removed amdgpu from + # services.xserver.videoDrivers by overriding. This is because the specialization + # of nix cannot implement such an operation as canceling an import. In the end, if + # it is enabled in Dual-Direct GFX In the absence of amd igpu, the amdvlk package + # caused the proton to crash. In order to solve this problem, I add the option of + # whether to enable amdvlk to the configuration file of amd gpu, and open it by + # default, and turn it off in specialization, so as to delete amdvlk package and + # other packages for amd igpu in specialization. At the same time, I also added an + # option to amdgpu's opencl runtime. hardware = { nvidia.prime.offload.enable = false; amdgpu = {