Skip to content

Instantly share code, notes, and snippets.

@cgmb
Last active Jul 14, 2019
Embed
What would you like to do?
Vulkan with Intel Graphics on Ubuntu 14.04
Section "Device"
Identifier "Intel Graphics"
Driver "intel"
Option "DRI" "3"
EndSection

Vulkan with Intel Graphics on Ubuntu 14.04

I've been hacking away, trying to get Vulkan working on my Ubuntu 14.04 laptop (Late-2013 MacBook Pro [11,2]). It's more or less working. vulkaninfo appears to complete without error, and both the LunarG example programs run, though with a number of warnings. At this point the problem is just that the vulkan driver is not finished for my hardware (Haswell).

Here are the steps I took to get some almost-working drivers.

  • Install LunarG's Vulkan SDK
  • Update to Linux Kernel 4.2 via the Ubuntu 14.04 LTS Enablement Stack
  • Enable DRI3 by copying 20-intel.conf above to /usr/share/X11/xorg.conf.d/20-intel.conf
  • Reboot and make sure that DRI3 is now mentioned in /var/log/Xorg.0.log
  • Checkout the vulkan branch of the mesa source code with git clone -b vulkan http://anongit.freedesktop.org/git/mesa/mesa.git
  • The newest versions depend on a slightly newer version of libdrm than comes with 14.04, so roll back the repository back to the latest working driver version with git reset --hard b83785d86d2c7f07323920615c72a9f09695a9a7
  • Apply the patch supplied below with git apply fix-missing-memfd-header.patch to correct for the missing memfd headers.
  • Install build dependencies listed on the mesa website. I thinksudo apt-get install python-mako bison flex build-essential autoconf covers everything that's needed.
  • Check the README in the mesa repository for up-to-date build instructions. At time of this writing, you can build with autoreconf -vfi && ./configure --with-dri-drivers=i965 --with-gallium-drivers= && make -j4. You can add --enable-debug to configure if you want a build that will print more detailed vkError messages.
  • I hacked around a permissions problem by running sudo chmod 666 /dev/dri/renderD128. Apparently there is supposed to be a script that adds your user to an access control list (ACL) on login. That doesn't seem to exist on Ubuntu 14.04, though.
  • Set VK_ICD_FILENAMES so the LunarG loader finds everything correctly. You'll need to do this in the same shell that runs your program. README.intel-vulkan.txt gives you a command, but it refers to a non-existent file. Instead use export VK_ICD_FILENAMES="$MESA_TOP/src/intel/vulkan/dev_icd.json", replacing $MESA_TOP with the absolute path of the directory containing the mesa source code.
  • You're done! Run vulkaninfo and/or try to run the VulkanSDK example cube. Instructions to build and run the latter are on the LunarG website.

My vulkaninfo and cube output are here for reference.

diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c
index 3b62bda..323341d 100644
--- a/src/intel/vulkan/anv_allocator.c
+++ b/src/intel/vulkan/anv_allocator.c
@@ -29,7 +29,15 @@
#include <values.h>
#include <assert.h>
#include <linux/futex.h>
-#include <linux/memfd.h>
+#ifndef _UAPI_LINUX_MEMFD_H
+#define _UAPI_LINUX_MEMFD_H
+
+/* flags for memfd_create(2) (unsigned int) */
+#define MFD_CLOEXEC 0x0001U
+#define MFD_ALLOW_SEALING 0x0002U
+
+#endif /* _UAPI_LINUX_MEMFD_H */
+#define SYS_memfd_create 319
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/syscall.h>
diff --git a/src/intel/vulkan/anv_gem_stubs.c b/src/intel/vulkan/anv_gem_stubs.c
index 3204fef..f89603a 100644
--- a/src/intel/vulkan/anv_gem_stubs.c
+++ b/src/intel/vulkan/anv_gem_stubs.c
@@ -23,7 +23,14 @@
#define _DEFAULT_SOURCE
-#include <linux/memfd.h>
+#ifndef _UAPI_LINUX_MEMFD_H
+#define _UAPI_LINUX_MEMFD_H
+
+/* flags for memfd_create(2) (unsigned int) */
+#define MFD_CLOEXEC 0x0001U
+#define MFD_ALLOW_SEALING 0x0002U
+#endif /* _UAPI_LINUX_MEMFD_H */
+#define SYS_memfd_create 319
#include <sys/mman.h>
#include <sys/syscall.h>
@lvasilis09
Copy link

lvasilis09 commented Mar 22, 2016

Hello,

First of all thanks for your guide, it is very useful. I have some problems trying to set Vulkan on my computer (Ububtu: 14.04 LTS, Kernel: 4.2.0-34-generic, DRI3).
I have followed your steps, and when I try to "make" it, I take the following errors:

  • many errors for missing prototypes: e.g. anv_device.c:208:10: error: no previous prototype for 'anv_CreateInstance' [-Werror=missing-prototypes]
    VkResult anv_CreateInstance(
  • this error: anv_private.h:486:14: error: 'struct anv_dispatch_table' has no member named 'DeviceWaitIdle'

Did you meet the same errors? I would appreciate it if you could help me, as I am trying for many days to get Vulkan working on my PC.

Thanks in advance,
Vasilis

@cgmb
Copy link
Author

cgmb commented Mar 23, 2016

@lvasilis09 I haven't seen those particular problems, but there have been updates to the repository since I originally wrote this. The latest version of mesa that I could get working is b83785d86d2c7f07323920615c72a9f09695a9a7. I've updated the instructions to check out that version.

If you struggle with it for too long, I might suggest waiting for Ubuntu 16.04. There is a PPA, which will make it much easier to get the drivers.

@mbinoy
Copy link

mbinoy commented Jul 7, 2017

excellent, thanks for this, got it working on Ubuntu 14.04 LTS with mesa drivers

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