From 29e2aac69088e3592b1f6c8f3dd14cf1a838bd7a Mon Sep 17 00:00:00 2001 From: nyorain Date: Mon, 24 Jul 2017 18:30:23 +0200 Subject: [PATCH 01/10] Add first vulkan dependency module --- mesonbuild/dependencies/__init__.py | 3 +- mesonbuild/dependencies/ui.py | 55 +++++++++++++++++++- test cases/frameworks/17 vulkan/meson.build | 7 +++ test cases/frameworks/17 vulkan/vulkanprog.c | 35 +++++++++++++ 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 test cases/frameworks/17 vulkan/meson.build create mode 100644 test cases/frameworks/17 vulkan/vulkanprog.c diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py index 3d41a2bd3..f153b976b 100644 --- a/mesonbuild/dependencies/__init__.py +++ b/mesonbuild/dependencies/__init__.py @@ -19,7 +19,7 @@ from .base import ( # noqa: F401 from .dev import GMockDependency, GTestDependency, LLVMDependency, ValgrindDependency from .misc import BoostDependency, Python3Dependency, ThreadDependency from .platform import AppleFrameworks -from .ui import GLDependency, GnuStepDependency, Qt4Dependency, Qt5Dependency, SDL2Dependency, WxDependency +from .ui import GLDependency, GnuStepDependency, Qt4Dependency, Qt5Dependency, SDL2Dependency, WxDependency, VulkanDependency packages.update({ @@ -44,4 +44,5 @@ packages.update({ 'qt5': Qt5Dependency, 'sdl2': SDL2Dependency, 'wxwidgets': WxDependency, + 'vulkan': VulkanDependency, }) diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index 1c59a416f..18a7996a2 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -24,7 +24,7 @@ from collections import OrderedDict from .. import mlog from .. import mesonlib from ..mesonlib import MesonException, Popen_safe, version_compare -from ..environment import for_windows +from ..environment import for_windows, detect_cpu from .base import DependencyException, DependencyMethods from .base import ExternalDependency, ExternalProgram @@ -493,3 +493,56 @@ class WxDependency(ExternalDependency): pass WxDependency.wxconfig_found = False mlog.log('Found wx-config:', mlog.red('NO')) + +class VulkanDependency(ExternalDependency): + def __init__(self, environment, kwargs): + super().__init__('vulkan', environment, None, kwargs) + + if DependencyMethods.SYSTEM in self.methods: + try: + self.vulkan_sdk = os.environ['VULKAN_SDK'] + if not os.path.isabs(self.vulkan_sdk): + raise DependencyException('VULKAN_SDK must be an absolute path.') + + # TODO: this config might not work on some platforms, fix bugs as reported + # we at least have to detect other 64-bit platforms (e.g. armv8) + lib_name = 'vulkan' + if mesonlib.is_windows(): + lib_name = 'vulkan-1' + + lib_dir = 'Lib32' + if detect_cpu({}) == 'x86_64': + lib_dir = 'Lib' + + self.type_name = 'vulkan_sdk' + self.is_found = True + self.compile_args.append('-I' + os.path.join(self.vulkan_sdk, 'Include')) + self.link_args.append('-L' + os.path.join(self.vulkan_sdk, lib_dir)) + self.link_args.append('-l' + lib_name) + + # TODO: find a way to retrieve this from the sdk + # we could try go guess it depending on the vulkan_sdk path + # usually the paths last component is the vulkan version + # but this might be modified at installation + self.version = '1' + return + except KeyError: + self.vulkan_sdk = None + + if DependencyMethods.PKGCONFIG in self.methods: + try: + pcdep = PkgConfigDependency('vulkan', environment, kwargs) + if pcdep.found(): + self.type_name = 'pkgconfig' + self.is_found = True + self.compile_args = pcdep.get_compile_args() + self.link_args = pcdep.get_link_args() + self.version = pcdep.get_version() + return + except Exception: + pass + + def get_methods(self): + return [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM] + + diff --git a/test cases/frameworks/17 vulkan/meson.build b/test cases/frameworks/17 vulkan/meson.build new file mode 100644 index 000000000..05e6ce714 --- /dev/null +++ b/test cases/frameworks/17 vulkan/meson.build @@ -0,0 +1,7 @@ +project('vulkan test', 'c') + +sdl2_dep = dependency('vulkan') + +e = executable('vulkanprog', 'vulkanprog.c', dependencies : sdl2_dep) + +test('vulkantest', e) diff --git a/test cases/frameworks/17 vulkan/vulkanprog.c b/test cases/frameworks/17 vulkan/vulkanprog.c new file mode 100644 index 000000000..86a3a204d --- /dev/null +++ b/test cases/frameworks/17 vulkan/vulkanprog.c @@ -0,0 +1,35 @@ +#include +#include + +int main() +{ + VkApplicationInfo application_info = { + VK_STRUCTURE_TYPE_APPLICATION_INFO, + NULL, + "sway", + VK_MAKE_VERSION(1,0,0), + "wlroots", + VK_MAKE_VERSION(1,0,0), + VK_MAKE_VERSION(1,0,0) + }; + + VkInstanceCreateInfo instance_create_info = { + VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, + NULL, + 0, + &application_info, + 0, + NULL, + 0, + NULL, + }; + + VkInstance instance; + VkResult ret = vkCreateInstance(&instance_create_info, NULL, &instance); + if(ret != VK_SUCCESS) { + printf("Could not create vulkan instance: %d\n", ret); + return ret; + } + + return 0; +} \ No newline at end of file From 2174027ba117dc5eae708342595de38dfedf1a53 Mon Sep 17 00:00:00 2001 From: nyorain Date: Mon, 24 Jul 2017 18:42:41 +0200 Subject: [PATCH 02/10] Fix whitespace issues --- mesonbuild/dependencies/ui.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index 18a7996a2..488e3a2a6 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -493,42 +493,42 @@ class WxDependency(ExternalDependency): pass WxDependency.wxconfig_found = False mlog.log('Found wx-config:', mlog.red('NO')) - + class VulkanDependency(ExternalDependency): def __init__(self, environment, kwargs): super().__init__('vulkan', environment, None, kwargs) - + if DependencyMethods.SYSTEM in self.methods: try: self.vulkan_sdk = os.environ['VULKAN_SDK'] if not os.path.isabs(self.vulkan_sdk): raise DependencyException('VULKAN_SDK must be an absolute path.') - + # TODO: this config might not work on some platforms, fix bugs as reported # we at least have to detect other 64-bit platforms (e.g. armv8) lib_name = 'vulkan' if mesonlib.is_windows(): lib_name = 'vulkan-1' - + lib_dir = 'Lib32' if detect_cpu({}) == 'x86_64': lib_dir = 'Lib' - + self.type_name = 'vulkan_sdk' self.is_found = True self.compile_args.append('-I' + os.path.join(self.vulkan_sdk, 'Include')) self.link_args.append('-L' + os.path.join(self.vulkan_sdk, lib_dir)) self.link_args.append('-l' + lib_name) - + # TODO: find a way to retrieve this from the sdk # we could try go guess it depending on the vulkan_sdk path # usually the paths last component is the vulkan version # but this might be modified at installation - self.version = '1' + self.version = '1' return except KeyError: self.vulkan_sdk = None - + if DependencyMethods.PKGCONFIG in self.methods: try: pcdep = PkgConfigDependency('vulkan', environment, kwargs) @@ -541,8 +541,6 @@ class VulkanDependency(ExternalDependency): return except Exception: pass - + def get_methods(self): return [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM] - - From 766024e334339782f7c515b7a089bc058275dcd2 Mon Sep 17 00:00:00 2001 From: nyorain Date: Mon, 24 Jul 2017 18:44:31 +0200 Subject: [PATCH 03/10] Fix wrong dep name in vulkan test --- test cases/frameworks/17 vulkan/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test cases/frameworks/17 vulkan/meson.build b/test cases/frameworks/17 vulkan/meson.build index 05e6ce714..869ae2f16 100644 --- a/test cases/frameworks/17 vulkan/meson.build +++ b/test cases/frameworks/17 vulkan/meson.build @@ -1,6 +1,6 @@ project('vulkan test', 'c') -sdl2_dep = dependency('vulkan') +vulkan_dep = dependency('vulkan') e = executable('vulkanprog', 'vulkanprog.c', dependencies : sdl2_dep) From 0aa71d680898fd2812a3038a57eb9f9231af1de4 Mon Sep 17 00:00:00 2001 From: nyorain Date: Mon, 24 Jul 2017 21:03:26 +0200 Subject: [PATCH 04/10] Fix vulkan test --- test cases/frameworks/17 vulkan/meson.build | 2 +- test cases/frameworks/17 vulkan/vulkanprog.c | 13 ++----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/test cases/frameworks/17 vulkan/meson.build b/test cases/frameworks/17 vulkan/meson.build index 869ae2f16..54f1d4746 100644 --- a/test cases/frameworks/17 vulkan/meson.build +++ b/test cases/frameworks/17 vulkan/meson.build @@ -2,6 +2,6 @@ project('vulkan test', 'c') vulkan_dep = dependency('vulkan') -e = executable('vulkanprog', 'vulkanprog.c', dependencies : sdl2_dep) +e = executable('vulkanprog', 'vulkanprog.c', dependencies : vulkan_dep) test('vulkantest', e) diff --git a/test cases/frameworks/17 vulkan/vulkanprog.c b/test cases/frameworks/17 vulkan/vulkanprog.c index 86a3a204d..af946defc 100644 --- a/test cases/frameworks/17 vulkan/vulkanprog.c +++ b/test cases/frameworks/17 vulkan/vulkanprog.c @@ -3,21 +3,11 @@ int main() { - VkApplicationInfo application_info = { - VK_STRUCTURE_TYPE_APPLICATION_INFO, - NULL, - "sway", - VK_MAKE_VERSION(1,0,0), - "wlroots", - VK_MAKE_VERSION(1,0,0), - VK_MAKE_VERSION(1,0,0) - }; - VkInstanceCreateInfo instance_create_info = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, NULL, 0, - &application_info, + NULL, 0, NULL, 0, @@ -31,5 +21,6 @@ int main() return ret; } + vkDestroyInstance(instance, NULL); return 0; } \ No newline at end of file From 0c2ef49dc504368dd4ff80545b38c2380391cd65 Mon Sep 17 00:00:00 2001 From: nyorain Date: Tue, 25 Jul 2017 21:49:01 +0200 Subject: [PATCH 05/10] Trigger travis --- mesonbuild/dependencies/ui.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index 488e3a2a6..d6392850d 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -505,7 +505,7 @@ class VulkanDependency(ExternalDependency): raise DependencyException('VULKAN_SDK must be an absolute path.') # TODO: this config might not work on some platforms, fix bugs as reported - # we at least have to detect other 64-bit platforms (e.g. armv8) + # we should at least detect other 64-bit platforms (e.g. armv8) lib_name = 'vulkan' if mesonlib.is_windows(): lib_name = 'vulkan-1' @@ -520,8 +520,8 @@ class VulkanDependency(ExternalDependency): self.link_args.append('-L' + os.path.join(self.vulkan_sdk, lib_dir)) self.link_args.append('-l' + lib_name) - # TODO: find a way to retrieve this from the sdk - # we could try go guess it depending on the vulkan_sdk path + # TODO: find a way to retrieve the version from the sdk? + # we could try go guess it depending on the vulkan_sdk path. # usually the paths last component is the vulkan version # but this might be modified at installation self.version = '1' From 005e0416452c980ef350371db56612a0f12f99dd Mon Sep 17 00:00:00 2001 From: nyorain Date: Tue, 25 Jul 2017 23:20:05 +0200 Subject: [PATCH 06/10] Fix vulkan module for linux Rework the vulkan module: - adopt the VULKAN_SDK paths for its linux version - add sanity tests for the VULKAN_SDK path - add guessing as last fallback, needed on linux systems on which no vulkan pkgconfig is installed [ubuntu atm] - restructure exception handling/branching Not tested on windows yet. --- mesonbuild/dependencies/ui.py | 64 +++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index d6392850d..1de743838 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -498,49 +498,71 @@ class VulkanDependency(ExternalDependency): def __init__(self, environment, kwargs): super().__init__('vulkan', environment, None, kwargs) + if DependencyMethods.PKGCONFIG in self.methods: + try: + pcdep = PkgConfigDependency('vulkan', environment, kwargs) + if pcdep.found(): + self.type_name = 'pkgconfig' + self.is_found = True + self.compile_args = pcdep.get_compile_args() + self.link_args = pcdep.get_link_args() + self.version = pcdep.get_version() + return + except Exception: + pass + if DependencyMethods.SYSTEM in self.methods: try: self.vulkan_sdk = os.environ['VULKAN_SDK'] if not os.path.isabs(self.vulkan_sdk): raise DependencyException('VULKAN_SDK must be an absolute path.') + except KeyError: + self.vulkan_sdk = None + if self.vulkan_sdk: # TODO: this config might not work on some platforms, fix bugs as reported # we should at least detect other 64-bit platforms (e.g. armv8) lib_name = 'vulkan' if mesonlib.is_windows(): lib_name = 'vulkan-1' + lib_dir = 'Lib32' + inc_dir = 'Include' + if detect_cpu({}) == 'x86_64': + lib_dir = 'Lib' + else: + lib_name = 'vulkan' + lib_dir = 'lib' + inc_dir = 'include' - lib_dir = 'Lib32' - if detect_cpu({}) == 'x86_64': - lib_dir = 'Lib' + # make sure header and lib are valid + inc_path = os.path.join(self.vulkan_sdk, inc_dir) + header = os.path.join(inc_path, 'vulkan', 'vulkan.h') + lib_path = os.path.join(self.vulkan_sdk, lib_dir) + find_lib = self.compiler.find_library('vulkan', environment, lib_path) + + if not (find_lib and os.path.isfile(header)): + raise DependencyException('VULKAN_SDK point to invalid directory') self.type_name = 'vulkan_sdk' self.is_found = True - self.compile_args.append('-I' + os.path.join(self.vulkan_sdk, 'Include')) - self.link_args.append('-L' + os.path.join(self.vulkan_sdk, lib_dir)) + self.compile_args.append('-I' + inc_path) + self.link_args.append('-L' + lib_path) self.link_args.append('-l' + lib_name) # TODO: find a way to retrieve the version from the sdk? - # we could try go guess it depending on the vulkan_sdk path. - # usually the paths last component is the vulkan version - # but this might be modified at installation + # Usually it is a part of the path to it (but does not have to be) self.version = '1' return - except KeyError: - self.vulkan_sdk = None - - if DependencyMethods.PKGCONFIG in self.methods: - try: - pcdep = PkgConfigDependency('vulkan', environment, kwargs) - if pcdep.found(): - self.type_name = 'pkgconfig' + else: + # simply try to guess it, usually works on linux + libs = self.compiler.find_library('vulkan', environment, []) + if libs != None and self.compiler.has_header('vulkan/vulkan.h', '', environment): + self.type_name = 'system' self.is_found = True - self.compile_args = pcdep.get_compile_args() - self.link_args = pcdep.get_link_args() - self.version = pcdep.get_version() + self.version = 1 # TODO + for lib in libs: + self.link_args.append(lib) return - except Exception: - pass def get_methods(self): return [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM] From 02e5c58efcea5efef9fc26bdce1dd4629ea96d68 Mon Sep 17 00:00:00 2001 From: nyorain Date: Tue, 25 Jul 2017 23:25:00 +0200 Subject: [PATCH 07/10] Fix style issue in vulkan dep --- mesonbuild/dependencies/ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index 1de743838..c182e8417 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -556,7 +556,7 @@ class VulkanDependency(ExternalDependency): else: # simply try to guess it, usually works on linux libs = self.compiler.find_library('vulkan', environment, []) - if libs != None and self.compiler.has_header('vulkan/vulkan.h', '', environment): + if libs is not None and self.compiler.has_header('vulkan/vulkan.h', '', environment): self.type_name = 'system' self.is_found = True self.version = 1 # TODO From 6dd9098cd7ed3ea49df8a0eb44e7aa02dd2d6f46 Mon Sep 17 00:00:00 2001 From: nyorain Date: Thu, 27 Jul 2017 12:05:08 +0200 Subject: [PATCH 08/10] Fix vulkan windows; Make test succeed w/o driver Fix an error in the windows vulkan_sdk library finding. Also don't fail the vulkan test only because no vulkan driver is installed (should fix the travis error). --- mesonbuild/dependencies/ui.py | 9 ++++++--- test cases/frameworks/17 vulkan/vulkanprog.c | 14 +++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index c182e8417..7e077c7dc 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -538,10 +538,13 @@ class VulkanDependency(ExternalDependency): inc_path = os.path.join(self.vulkan_sdk, inc_dir) header = os.path.join(inc_path, 'vulkan', 'vulkan.h') lib_path = os.path.join(self.vulkan_sdk, lib_dir) - find_lib = self.compiler.find_library('vulkan', environment, lib_path) + find_lib = self.compiler.find_library(lib_name, environment, lib_path) - if not (find_lib and os.path.isfile(header)): - raise DependencyException('VULKAN_SDK point to invalid directory') + if not find_lib: + raise DependencyException('VULKAN_SDK point to invalid directory (no lib)') + + if not os.path.isfile(header): + raise DependencyException('VULKAN_SDK point to invalid directory (no include)') self.type_name = 'vulkan_sdk' self.is_found = True diff --git a/test cases/frameworks/17 vulkan/vulkanprog.c b/test cases/frameworks/17 vulkan/vulkanprog.c index af946defc..1c1c58aae 100644 --- a/test cases/frameworks/17 vulkan/vulkanprog.c +++ b/test cases/frameworks/17 vulkan/vulkanprog.c @@ -14,13 +14,13 @@ int main() NULL, }; + // we don't actually require instance creation to succeed since + // we cannot expect test environments to have a vulkan driver installed. + // As long as this does not produce as segmentation fault or similar, + // everything's alright. VkInstance instance; - VkResult ret = vkCreateInstance(&instance_create_info, NULL, &instance); - if(ret != VK_SUCCESS) { - printf("Could not create vulkan instance: %d\n", ret); - return ret; - } - - vkDestroyInstance(instance, NULL); + if(vkCreateInstance(&instance_create_info, NULL, &instance) == VK_SUCCESS) + vkDestroyInstance(instance, NULL); + return 0; } \ No newline at end of file From ec445c35988c19b080f6f82bd96054c2d27f5eae Mon Sep 17 00:00:00 2001 From: nyorain Date: Thu, 27 Jul 2017 12:10:12 +0200 Subject: [PATCH 09/10] Fix vulkan style issue --- mesonbuild/dependencies/ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index 7e077c7dc..99e017b38 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -542,7 +542,7 @@ class VulkanDependency(ExternalDependency): if not find_lib: raise DependencyException('VULKAN_SDK point to invalid directory (no lib)') - + if not os.path.isfile(header): raise DependencyException('VULKAN_SDK point to invalid directory (no include)') From 12a5a50058cc3c6184d2d02a60dc578c2ec5d8d8 Mon Sep 17 00:00:00 2001 From: nyorain Date: Fri, 4 Aug 2017 19:50:36 +0200 Subject: [PATCH 10/10] Add vulkan dependency to release notes --- docs/markdown/Release-notes-for-0.42.0.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/markdown/Release-notes-for-0.42.0.md b/docs/markdown/Release-notes-for-0.42.0.md index f0ea534c1..9b2df63c2 100644 --- a/docs/markdown/Release-notes-for-0.42.0.md +++ b/docs/markdown/Release-notes-for-0.42.0.md @@ -83,3 +83,8 @@ flag manually, e.g. via `link_args` to a target. This is not recommended because having multiple rpath causes them to stomp on each other. This warning will become a hard error in some future release. +## Vulkan dependency module + +Vulkan can now be used as native dependency. The dependency module will detect +the VULKAN_SDK environment variable or otherwise try to receive the vulkan +library and header via pkgconfig or from the system.