summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2021-08-12 14:24:54 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2021-08-12 14:25:15 +0300
commitd7957a2a2091a00c8ccdebb6900e5a0f21aa205d (patch)
tree86b99a97ef9540d46183ac9667c58cb124880821 /drivers
parent67fc611bda7b55b3eeab87f683a5c95ea0d0313f (diff)
Use "volk" instead of statically linked Vulkan loader.
Diffstat (limited to 'drivers')
-rw-r--r--drivers/vulkan/SCsub140
-rw-r--r--drivers/vulkan/rendering_device_vulkan.cpp2
-rw-r--r--drivers/vulkan/rendering_device_vulkan.h4
-rw-r--r--drivers/vulkan/vulkan_context.cpp9
-rw-r--r--drivers/vulkan/vulkan_context.h4
5 files changed, 56 insertions, 103 deletions
diff --git a/drivers/vulkan/SCsub b/drivers/vulkan/SCsub
index 6a2a57d18c..3e0f5788c3 100644
--- a/drivers/vulkan/SCsub
+++ b/drivers/vulkan/SCsub
@@ -3,116 +3,52 @@
Import("env")
thirdparty_obj = []
+thirdparty_dir = "#thirdparty/vulkan"
+thirdparty_volk_dir = "#thirdparty/volk"
-# FIXME: Refactor all this to reduce code duplication.
-if env["platform"] == "android":
+if env["use_volk"]:
+ env.AppendUnique(CPPDEFINES=["USE_VOLK"])
+ env.Prepend(CPPPATH=[thirdparty_volk_dir])
+
+if env["platform"] == "android" and not env["use_volk"]:
# Use NDK Vulkan headers
- thirdparty_dir = env["ANDROID_NDK_ROOT"] + "/sources/third_party/vulkan/src"
+ ndk_vulkan_dir = env["ANDROID_NDK_ROOT"] + "/sources/third_party/vulkan/src"
thirdparty_includes = [
- thirdparty_dir,
- thirdparty_dir + "/include",
- thirdparty_dir + "/layers",
- thirdparty_dir + "/layers/generated",
+ ndk_vulkan_dir,
+ ndk_vulkan_dir + "/include",
+ ndk_vulkan_dir + "/layers",
+ ndk_vulkan_dir + "/layers/generated",
]
env.Prepend(CPPPATH=thirdparty_includes)
-
- # Build Vulkan memory allocator
- env_thirdparty = env.Clone()
- env_thirdparty.disable_warnings()
-
- thirdparty_dir = "#thirdparty/vulkan"
- vma_sources = [thirdparty_dir + "/android/vk_mem_alloc.cpp"]
- env_thirdparty.add_source_files(thirdparty_obj, vma_sources)
-
-elif env["platform"] == "iphone":
- # Use bundled Vulkan headers
- thirdparty_dir = "#thirdparty/vulkan"
- env.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include", thirdparty_dir + "/loader"])
-
- # Build Vulkan memory allocator
- env_thirdparty = env.Clone()
- env_thirdparty.disable_warnings()
-
- vma_sources = [thirdparty_dir + "/vk_mem_alloc.cpp"]
- env_thirdparty.add_source_files(thirdparty_obj, vma_sources)
-
-elif env["builtin_vulkan"]:
+else:
# Use bundled Vulkan headers
- thirdparty_dir = "#thirdparty/vulkan"
- env.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include", thirdparty_dir + "/loader"])
-
- # Build Vulkan loader library
- env_thirdparty = env.Clone()
- env_thirdparty.disable_warnings()
-
- loader_sources = [
- "cJSON.c",
- "debug_utils.c",
- "dev_ext_trampoline.c",
- "loader.c",
- "murmurhash.c",
- "phys_dev_ext.c",
- "trampoline.c",
- "unknown_ext_chain.c",
- "wsi.c",
- "extension_manual.c",
- ]
- vma_sources = [thirdparty_dir + "/vk_mem_alloc.cpp"]
-
- if env["platform"] == "windows":
- loader_sources.append("dirent_on_windows.c")
- env_thirdparty.AppendUnique(
- CPPDEFINES=[
- "VK_USE_PLATFORM_WIN32_KHR",
- "VULKAN_NON_CMAKE_BUILD",
- "WIN32_LEAN_AND_MEAN",
- 'API_NAME=\\"%s\\"' % "Vulkan",
- ]
- )
- if not env.msvc: # Windows 7+, missing in mingw headers
- env_thirdparty.AppendUnique(
- CPPDEFINES=["CM_GETIDLIST_FILTER_CLASS=0x00000200", "CM_GETIDLIST_FILTER_PRESENT=0x00000100"]
- )
- elif env["platform"] == "osx":
- env_thirdparty.AppendUnique(
- CPPDEFINES=[
- "VK_USE_PLATFORM_MACOS_MVK",
- "VULKAN_NON_CMAKE_BUILD",
- 'SYSCONFDIR=\\"%s\\"' % "/etc",
- 'FALLBACK_DATA_DIRS=\\"%s\\"' % "/usr/local/share:/usr/share",
- 'FALLBACK_CONFIG_DIRS=\\"%s\\"' % "/etc/xdg",
- ]
- )
- elif env["platform"] == "linuxbsd":
- env_thirdparty.AppendUnique(
- CPPDEFINES=[
- "VK_USE_PLATFORM_XLIB_KHR",
- "VULKAN_NON_CMAKE_BUILD",
- 'SYSCONFDIR=\\"%s\\"' % "/etc",
- 'FALLBACK_DATA_DIRS=\\"%s\\"' % "/usr/local/share:/usr/share",
- 'FALLBACK_CONFIG_DIRS=\\"%s\\"' % "/etc/xdg",
- ]
- )
- import platform
-
- if platform.system() == "Linux":
- # In glibc since 2.17 and musl libc since 1.1.24. Used by loader.c.
- env_thirdparty.AppendUnique(CPPDEFINES=["HAVE_SECURE_GETENV"])
-
- loader_sources = [thirdparty_dir + "/loader/" + file for file in loader_sources]
- env_thirdparty.add_source_files(thirdparty_obj, loader_sources)
- env_thirdparty.add_source_files(thirdparty_obj, vma_sources)
-
-else: # Always build VMA.
- thirdparty_dir = "#thirdparty/vulkan"
env.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include"])
- # Build Vulkan loader library
- env_thirdparty = env.Clone()
- env_thirdparty.disable_warnings()
- vma_sources = [thirdparty_dir + "/vk_mem_alloc.cpp"]
-
- env_thirdparty.add_source_files(thirdparty_obj, vma_sources)
+if env["platform"] == "android":
+ env.AppendUnique(CPPDEFINES=["VK_USE_PLATFORM_ANDROID_KHR"])
+elif env["platform"] == "iphone":
+ env.AppendUnique(CPPDEFINES=["VK_USE_PLATFORM_IOS_MVK"])
+elif env["platform"] == "linuxbsd":
+ env.AppendUnique(CPPDEFINES=["VK_USE_PLATFORM_XLIB_KHR"])
+elif env["platform"] == "osx":
+ env.AppendUnique(CPPDEFINES=["VK_USE_PLATFORM_MACOS_MVK"])
+elif env["platform"] == "windows":
+ env.AppendUnique(CPPDEFINES=["VK_USE_PLATFORM_WIN32_KHR"])
+
+# Build Vulkan memory allocator and volk
+env_thirdparty_vma = env.Clone()
+env_thirdparty_vma.disable_warnings()
+thirdparty_sources_vma = [thirdparty_dir + "/vk_mem_alloc.cpp"]
+
+if env["use_volk"]:
+ env_thirdparty_vma.AppendUnique(CPPDEFINES=["VMA_STATIC_VULKAN_FUNCTIONS=1"])
+ env_thirdparty_volk = env.Clone()
+ env_thirdparty_volk.disable_warnings()
+
+ thirdparty_sources_volk = [thirdparty_volk_dir + "/volk.c"]
+ env_thirdparty_volk.add_source_files(thirdparty_obj, thirdparty_sources_volk)
+
+env_thirdparty_vma.add_source_files(thirdparty_obj, thirdparty_sources_vma)
env.drivers_sources += thirdparty_obj
diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp
index 38bb023f83..f6677e2da4 100644
--- a/drivers/vulkan/rendering_device_vulkan.cpp
+++ b/drivers/vulkan/rendering_device_vulkan.cpp
@@ -3825,7 +3825,7 @@ RenderingDevice::FramebufferFormatID RenderingDeviceVulkan::framebuffer_format_c
VkRenderPass render_pass;
VkResult res = vkCreateRenderPass(device, &render_pass_create_info, nullptr, &render_pass);
- ERR_FAIL_COND_V_MSG(res, VK_NULL_HANDLE, "vkCreateRenderPass for empty fb failed with error " + itos(res) + ".");
+ ERR_FAIL_COND_V_MSG(res, 0, "vkCreateRenderPass for empty fb failed with error " + itos(res) + ".");
if (render_pass == VK_NULL_HANDLE) { //was likely invalid
return INVALID_ID;
diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h
index dc4583d837..6175369285 100644
--- a/drivers/vulkan/rendering_device_vulkan.h
+++ b/drivers/vulkan/rendering_device_vulkan.h
@@ -44,7 +44,11 @@
#endif
#include "vk_mem_alloc.h"
+#ifdef USE_VOLK
+#include <volk.h>
+#else
#include <vulkan/vulkan.h>
+#endif
class VulkanContext;
diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp
index a9d0fb6fed..87749450c4 100644
--- a/drivers/vulkan/vulkan_context.cpp
+++ b/drivers/vulkan/vulkan_context.cpp
@@ -681,6 +681,10 @@ Error VulkanContext::_create_physical_device() {
inst_initialized = true;
+#ifdef USE_VOLK
+ volkLoadInstance(inst);
+#endif
+
/* Make initial call to query gpu_count, then second call for gpu info*/
err = vkEnumeratePhysicalDevices(inst, &gpu_count, nullptr);
ERR_FAIL_COND_V(err, ERR_CANT_CREATE);
@@ -1669,6 +1673,11 @@ Error VulkanContext::_update_swap_chain(Window *window) {
}
Error VulkanContext::initialize() {
+#ifdef USE_VOLK
+ if (volkInitialize() != VK_SUCCESS) {
+ return FAILED;
+ }
+#endif
Error err = _create_physical_device();
if (err) {
return err;
diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h
index 83e9524046..1690b853e3 100644
--- a/drivers/vulkan/vulkan_context.h
+++ b/drivers/vulkan/vulkan_context.h
@@ -38,7 +38,11 @@
#include "core/templates/rid_owner.h"
#include "servers/display_server.h"
+#ifdef USE_VOLK
+#include <volk.h>
+#else
#include <vulkan/vulkan.h>
+#endif
class VulkanContext {
public: