Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amdvlk: init at 2020.Q2.5 #82305

Merged
merged 1 commit into from Jun 25, 2020
Merged

amdvlk: init at 2020.Q2.5 #82305

merged 1 commit into from Jun 25, 2020

Conversation

Flakebi
Copy link
Member

@Flakebi Flakebi commented Mar 11, 2020

Motivation for this change

AMDVLK is the official open source Vulkan driver from AMD.
The share/vulkan/icd.d/amd_icd64.json file makes this the default driver if amdvlk is added to environment.systemPackages.
(To switch between multiple drivers setting export VK_ICD_FILENAMES=/nix/store/<hash>-amdvlk-2020.Q1.2/share/vulkan/icd.d/amd_icd64.json can be used.)

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@Flakebi
Copy link
Member Author

Flakebi commented Mar 23, 2020

@ashkitten: Thanks for taking a look at this, I updated the package to 2020.Q1.3 and the hash should be correct now.

@ashkitten
Copy link
Contributor

when i set environment.variables.VK_ICD_FILENAMES = "${pkgs.amdvlk}/share/vulkan/icd.d/amd_icd64.json" and reboot, running vulkaninfo gives me a segfault, as well as vkcube. do these only work with mesa, or is there something wrong with my setup?

@Flakebi
Copy link
Member Author

Flakebi commented Mar 24, 2020

vkcube and vulkaninfo both work with amdvlk and there is nothing particularly wrong with your setup but there are a few weird errors.

If $DISPLAY is not set, vulkaninfo works fine with amdvlk and radv.
If $DISPLAY is set, vulkaninfo only works with amdvlk if the following packages are in $LD_LIBRARY_PATH: xorg.libX11.
If $DISPLAY is set, vkcube only works with amdvlk if the following packages are in $LD_LIBRARY_PATH: xorg.libX11, xorg.libxcb, xorg.libxshmfence.
$WAYLAND_DISPLAY is ignored by both, they only work with xwayland.

I also tested the code of a simple Vulkan tutorial with SDL (with Wayland support).
If $WAYLAND_DISPLAY is set, works out-of-the-box with amdvlk and radv.
If only $DISPLAY is set on xwayland, it hangs somewhere when presenting the swapchain, happens for amdvlk and radv.

I added these libraries to the rpath, so vkcube and vulkaninfo should now work without any extra configuration.

@ashkitten
Copy link
Contributor

interesting that they work fine with radv anyways

@ashkitten
Copy link
Contributor

can confirm that it works now, by the way

@ashkitten
Copy link
Contributor

just tried to build this on my laptop and it says that the sha256 is invalid again. i'm not sure how repo projects work, but the hash seems to be unstable which is an issue.

@Flakebi
Copy link
Member Author

Flakebi commented Mar 31, 2020

Thank you for all the testing!
You are right and I now see why. The repository that contains the repo manifest also is included in the repo: https://github.com/GPUOpen-Drivers/AMDVLK/blob/v-2020.Q1.3/default.xml#L16
But as it is hard to reference itself, it just references master, which of course changes everytime a new release gets pushed.

Possibilities to fix this are

  1. Extend fetchRepoProject to support overriding fetched repositories with a fixed revision, this would allow us to pin the AMDVLK repository so the hash should not change anymore.
  2. Convince upstream to do two commits for every release and reference the first commit in the default.xml so we can get reproducible builds.
  3. Push our own default.xml file to nixpkgs which is based on the upstream one but contains a fixed hash for AMDVLK.

I think 3 is the easiest way to fix this. @ashkitten, what do you think?

@ashkitten
Copy link
Contributor

that sounds reasonable.

@Flakebi
Copy link
Member Author

Flakebi commented May 14, 2020

Many releases later, we are now at 2020.Q2.3 and the package declaration got slimmer 🎉.
Can someone maybe merge this?

@Flakebi Flakebi changed the title amdvlk: init at 2020.Q1.2 amdvlk: init at 2020.Q2.4 May 28, 2020
@Flakebi
Copy link
Member Author

Flakebi commented May 28, 2020

Updated to 2020.Q2.4.
@Ma27, could you or someone else maybe merge this please? Thanks!

@SFrijters
Copy link
Member

Don't have the power to merge anything I'm afraid, but I just wanted to note that I tried this just now to play with the new Path of Exile Vulkan beta (RADV crashes) and it worked wonderfully.

@alexarice
Copy link
Contributor

Can also confirm this works for me

@alexarice
Copy link
Contributor

Perhaps there should be a module that sets it up correctly?

@Flakebi
Copy link
Member Author

Flakebi commented Jun 6, 2020

Thanks for trying it out!

Perhaps there should be a module that sets it up correctly?

Putting the packages into environment.systemPackages makes it the default vulkan driver for me, is that what you mean?

@alexarice
Copy link
Contributor

I didn't actually try that and just went straight to setting the environment variable, I was thinking of a module that would set that environment variable for you but I guess if adding it to systemPackages works then this is not necessary

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/packaging-amdvlk/4795/5

@ldesgoui
Copy link
Contributor

Hello,

Great work, this works well on my R9 390.
vulkan-loader will find amd_icd64.json if I simply add the package to environment.systemPackages, but it won't pick it, supposedly because it finds stuff in /run/opengl-driver first.

@Flakebi
Copy link
Member Author

Flakebi commented Jun 13, 2020

I tried a few things and while it doesn’t change anything, adding amdvlk to hardware.opengl.extraPackages seems like a cleaner way than environment.systemPackages.
Adding it to any of those means both, radv/mesa and amdvlk will be found and exposed as possible GPUs. vulkaninfo | grep GPU (part of vulkan-tools) looks like this for me:

…
GPU id : 0 (AMD Radeon (TM) RX 480 Graphics):
GPU id : 1 (AMD RADV POLARIS10 (LLVM 9.0.1)):
GPU id : 0 (AMD Radeon (TM) RX 480 Graphics):
GPU id : 1 (AMD RADV POLARIS10 (LLVM 9.0.1)):
…

Every application decides itself which GPU/which driver it uses or it allows the user to choose. To force a certain driver, e.g. amdvlk or radv, setting

# amdvlk
VK_ICD_FILENAMES=/run/opengl-driver/share/vulkan/icd.d/amd_icd64.json
# or radv
VK_ICD_FILENAMES=/run/opengl-driver/share/vulkan/icd.d/radeon_icd.x86_64.json

can be used. If amdvlk is in environment.systemPackages instead of hardware.opengl.extraPackages it would be VK_ICD_FILENAMES=/run/current-system/sw/share/vulkan/icd.d/amd_icd64.json.
Running env VK_ICD_FILENAMES=/run/opengl-driver/share/vulkan/icd.d/amd_icd64.json vulkaninfo | grep GPU can be used to confirm the driver(s) in use.

@xvapx
Copy link
Contributor

xvapx commented Jun 24, 2020

Working well on my system too.
I'm using environment.variables.VK_ICD_FILENAMES = "${amdvlk}/share/vulkan/icd.d/amd_icd64.json";

@Flakebi Flakebi changed the title amdvlk: init at 2020.Q2.4 amdvlk: init at 2020.Q2.5 Jun 24, 2020
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-already-reviewed/2617/173

Copy link
Contributor

@danieldk danieldk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting this and for sending a reminder on discourse. I have added some more suggested changes.


nativeBuildInputs = [
cmake
ninja
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to compile without ninja?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review!
ninja is picked up by CMake automatically and for a project of this size (I’m looking at you llvm), ninja should be considerably faster than make.

I fixed all the other things you noticed.

pkgs/development/libraries/amdvlk/default.nix Outdated Show resolved Hide resolved
pkgs/development/libraries/amdvlk/default.nix Outdated Show resolved Hide resolved
pkgs/development/libraries/amdvlk/default.nix Outdated Show resolved Hide resolved
pkgs/development/libraries/amdvlk/default.nix Outdated Show resolved Hide resolved
@Flakebi
Copy link
Member Author

Flakebi commented Jun 25, 2020

Also, tested with

nixpkgs-review rev HEAD
$ export VK_ICD_FILENAMES=results/amdvlk/share/vulkan/icd.d/amd_icd64.json
$ export DISPLAY=:1
$ vkcube

and it still works.

Copy link
Contributor

@danieldk danieldk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Result of nixpkgs-review pr 82305 1

1 package built:
- amdvlk

Thanks for pushing this forward! I don't have an AMD GPU, but there are three confirmations that this works.

It would be nice if enabling the AMD Vulkan driver could be documented somewhere (perhaps the handbook or wiki?).

@danieldk danieldk merged commit 80b6b9b into NixOS:master Jun 25, 2020
@Flakebi Flakebi deleted the amdvlk branch June 25, 2020 13:30
@zeratax zeratax mentioned this pull request Jul 12, 2020
@Narice
Copy link
Contributor

Narice commented Sep 11, 2020

so, to enable the vulkan drivers, you just need to add amdvlk to hardware.opengl.extraPackages and then it's done ?
does this work with both radeon and amdgpu drivers ?

@danieldk
Copy link
Contributor

danieldk commented Sep 11, 2020

so, to enable the vulkan drivers, you just need to add amdvlk to hardware.opengl.extraPackages and then it's done ?

You don't actually have to do anything to use Vulkan drivers ;). If you have hardware.opengl.enable = true;, the Mesa Vulkan driver for amdgpu will be used. By putting amdvlk in extraPackages, you add this driver as an additional option.

@Flakebi
Copy link
Member Author

Flakebi commented Sep 11, 2020

I think both, RADV (the default AMD Vulkan driver which is part of mesa and installed when you set hardware.opengl.enable = true;) and amdvlk need the amdgpu kernel module, i.e. they do not work on pre-GCN GPUs where only the radeon kernel module is supported.
For early GCN GPUs, the amdgpu driver has to be explicitly enabled: https://wiki.archlinux.org/index.php/AMDGPU#Enable_Southern_Islands_(SI)_and_Sea_Islands_(CIK)_support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants