From be302e795776e7da064404ce5913d2083e58f04d Mon Sep 17 00:00:00 2001 From: Gergely Kis Date: Thu, 26 Sep 2024 21:46:48 +0200 Subject: [PATCH] Move Vulkan includes to a central godot_vulkan.h header Also fixes Vulkan build problem with recent Clang. (cherry picked from commit 146ba4106f459fd37d130a34da02ef737ac166e4) --- drivers/vulkan/godot_vulkan.h | 42 +++++++++++++++++++ drivers/vulkan/vulkan_hooks.h | 6 +-- platform/android/vulkan_context_android.cpp | 6 +-- platform/ios/display_server_ios.h | 6 +-- platform/ios/os_ios.mm | 6 +-- platform/linuxbsd/x11/vulkan_context_x11.cpp | 6 +-- platform/macos/vulkan_context_macos.mm | 6 +-- platform/windows/vulkan_context_win.cpp | 6 +-- ...VKEnumStringHelper-use-godot-vulkan.patch} | 11 +++-- ...-volk.patch => VMA-use-godot-vulkan.patch} | 10 ++--- thirdparty/vulkan/vk_enum_string_helper.h | 6 +-- thirdparty/vulkan/vk_mem_alloc.h | 6 +-- 12 files changed, 60 insertions(+), 57 deletions(-) create mode 100644 drivers/vulkan/godot_vulkan.h rename thirdparty/vulkan/patches/{VKEnumStringHelper-use-volk.patch => VKEnumStringHelper-use-godot-vulkan.patch} (65%) rename thirdparty/vulkan/patches/{VMA-use-volk.patch => VMA-use-godot-vulkan.patch} (59%) diff --git a/drivers/vulkan/godot_vulkan.h b/drivers/vulkan/godot_vulkan.h new file mode 100644 index 00000000000..f911c5520a8 --- /dev/null +++ b/drivers/vulkan/godot_vulkan.h @@ -0,0 +1,42 @@ +/**************************************************************************/ +/* godot_vulkan.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef GODOT_VULKAN_H +#define GODOT_VULKAN_H + +#ifdef USE_VOLK +#include +#else +#include +#define VK_NO_STDINT_H +#include +#endif + +#endif // GODOT_VULKAN_H diff --git a/drivers/vulkan/vulkan_hooks.h b/drivers/vulkan/vulkan_hooks.h index eaa52658e4c..f4a25fb349a 100644 --- a/drivers/vulkan/vulkan_hooks.h +++ b/drivers/vulkan/vulkan_hooks.h @@ -31,11 +31,7 @@ #ifndef VULKAN_HOOKS_H #define VULKAN_HOOKS_H -#ifdef USE_VOLK -#include -#else -#include -#endif +#include "drivers/vulkan/godot_vulkan.h" class VulkanHooks { public: diff --git a/platform/android/vulkan_context_android.cpp b/platform/android/vulkan_context_android.cpp index 01e6d144381..8f89dd2afbc 100644 --- a/platform/android/vulkan_context_android.cpp +++ b/platform/android/vulkan_context_android.cpp @@ -32,11 +32,7 @@ #ifdef VULKAN_ENABLED -#ifdef USE_VOLK -#include -#else -#include -#endif +#include "drivers/vulkan/godot_vulkan.h" const char *VulkanContextAndroid::_get_platform_surface_extension() const { return VK_KHR_ANDROID_SURFACE_EXTENSION_NAME; diff --git a/platform/ios/display_server_ios.h b/platform/ios/display_server_ios.h index be4ea1e6abe..eb445970d92 100644 --- a/platform/ios/display_server_ios.h +++ b/platform/ios/display_server_ios.h @@ -40,11 +40,7 @@ #include "drivers/vulkan/rendering_device_vulkan.h" #include "servers/rendering/renderer_rd/renderer_compositor_rd.h" -#ifdef USE_VOLK -#include -#else -#include -#endif +#include "drivers/vulkan/godot_vulkan.h" #endif // VULKAN_ENABLED #if defined(GLES3_ENABLED) diff --git a/platform/ios/os_ios.mm b/platform/ios/os_ios.mm index 16ac3acbec2..3a90eb8eb63 100644 --- a/platform/ios/os_ios.mm +++ b/platform/ios/os_ios.mm @@ -54,11 +54,7 @@ #include "servers/rendering/renderer_rd/renderer_compositor_rd.h" #import -#ifdef USE_VOLK -#include -#else -#include -#endif +#include "drivers/vulkan/godot_vulkan.h" #endif // Initialization order between compilation units is not guaranteed, diff --git a/platform/linuxbsd/x11/vulkan_context_x11.cpp b/platform/linuxbsd/x11/vulkan_context_x11.cpp index d240480f61d..547fc8091e8 100644 --- a/platform/linuxbsd/x11/vulkan_context_x11.cpp +++ b/platform/linuxbsd/x11/vulkan_context_x11.cpp @@ -32,11 +32,7 @@ #include "vulkan_context_x11.h" -#ifdef USE_VOLK -#include -#else -#include -#endif +#include "drivers/vulkan/godot_vulkan.h" const char *VulkanContextX11::_get_platform_surface_extension() const { return VK_KHR_XLIB_SURFACE_EXTENSION_NAME; diff --git a/platform/macos/vulkan_context_macos.mm b/platform/macos/vulkan_context_macos.mm index 46a2d9f86ac..c259c4bbd60 100644 --- a/platform/macos/vulkan_context_macos.mm +++ b/platform/macos/vulkan_context_macos.mm @@ -32,11 +32,7 @@ #ifdef VULKAN_ENABLED -#ifdef USE_VOLK -#include -#else -#include -#endif +#include "drivers/vulkan/godot_vulkan.h" const char *VulkanContextMacOS::_get_platform_surface_extension() const { return VK_MVK_MACOS_SURFACE_EXTENSION_NAME; diff --git a/platform/windows/vulkan_context_win.cpp b/platform/windows/vulkan_context_win.cpp index a60055dbec5..db578aa932e 100644 --- a/platform/windows/vulkan_context_win.cpp +++ b/platform/windows/vulkan_context_win.cpp @@ -32,11 +32,7 @@ #include "vulkan_context_win.h" -#ifdef USE_VOLK -#include -#else -#include -#endif +#include "drivers/vulkan/godot_vulkan.h" const char *VulkanContextWindows::_get_platform_surface_extension() const { return VK_KHR_WIN32_SURFACE_EXTENSION_NAME; diff --git a/thirdparty/vulkan/patches/VKEnumStringHelper-use-volk.patch b/thirdparty/vulkan/patches/VKEnumStringHelper-use-godot-vulkan.patch similarity index 65% rename from thirdparty/vulkan/patches/VKEnumStringHelper-use-volk.patch rename to thirdparty/vulkan/patches/VKEnumStringHelper-use-godot-vulkan.patch index 1cd2b60cd82..012668ae717 100644 --- a/thirdparty/vulkan/patches/VKEnumStringHelper-use-volk.patch +++ b/thirdparty/vulkan/patches/VKEnumStringHelper-use-godot-vulkan.patch @@ -1,17 +1,16 @@ diff --git a/thirdparty/vulkan/vk_enum_string_helper.h b/thirdparty/vulkan/vk_enum_string_helper.h -index 8c77dd3ee5..be968c091d 100644 +index 8c77dd3ee5..74f49a6430 100644 --- a/thirdparty/vulkan/vk_enum_string_helper.h +++ b/thirdparty/vulkan/vk_enum_string_helper.h -@@ -23,7 +23,11 @@ +@@ -22,8 +22,10 @@ + ****************************************************************************/ // NOLINTBEGIN #pragma once ++#ifdef __cplusplus #include -#include -+#ifdef USE_VOLK -+ #include -+#else -+ #include +#endif ++#include "drivers/vulkan/godot_vulkan.h" static inline bool IsDuplicatePnext(VkStructureType input_value) { switch (input_value) { diff --git a/thirdparty/vulkan/patches/VMA-use-volk.patch b/thirdparty/vulkan/patches/VMA-use-godot-vulkan.patch similarity index 59% rename from thirdparty/vulkan/patches/VMA-use-volk.patch rename to thirdparty/vulkan/patches/VMA-use-godot-vulkan.patch index 3a66157e1d6..0d0de24c0d2 100644 --- a/thirdparty/vulkan/patches/VMA-use-volk.patch +++ b/thirdparty/vulkan/patches/VMA-use-godot-vulkan.patch @@ -1,17 +1,13 @@ diff --git a/thirdparty/vulkan/vk_mem_alloc.h b/thirdparty/vulkan/vk_mem_alloc.h -index fa4298b23c..a29bf6dfb6 100644 +index fa4298b23c..146895fd90 100644 --- a/thirdparty/vulkan/vk_mem_alloc.h +++ b/thirdparty/vulkan/vk_mem_alloc.h -@@ -126,7 +126,11 @@ See documentation chapter: \ref statistics. +@@ -126,7 +126,7 @@ See documentation chapter: \ref statistics. extern "C" { #endif -#include -+#ifdef USE_VOLK -+ #include -+#else -+ #include -+#endif ++#include "drivers/vulkan/godot_vulkan.h" #if !defined(VMA_VULKAN_VERSION) #if defined(VK_VERSION_1_3) diff --git a/thirdparty/vulkan/vk_enum_string_helper.h b/thirdparty/vulkan/vk_enum_string_helper.h index be968c091d6..74f49a64302 100644 --- a/thirdparty/vulkan/vk_enum_string_helper.h +++ b/thirdparty/vulkan/vk_enum_string_helper.h @@ -22,12 +22,10 @@ ****************************************************************************/ // NOLINTBEGIN #pragma once +#ifdef __cplusplus #include -#ifdef USE_VOLK - #include -#else - #include #endif +#include "drivers/vulkan/godot_vulkan.h" static inline bool IsDuplicatePnext(VkStructureType input_value) { switch (input_value) { diff --git a/thirdparty/vulkan/vk_mem_alloc.h b/thirdparty/vulkan/vk_mem_alloc.h index 42fa3da29ec..146895fd90f 100644 --- a/thirdparty/vulkan/vk_mem_alloc.h +++ b/thirdparty/vulkan/vk_mem_alloc.h @@ -126,11 +126,7 @@ See documentation chapter: \ref statistics. extern "C" { #endif -#ifdef USE_VOLK - #include -#else - #include -#endif +#include "drivers/vulkan/godot_vulkan.h" #if !defined(VMA_VULKAN_VERSION) #if defined(VK_VERSION_1_3)