From c3a277097ab2076a18dde2ba98085a6b0a8e154b 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/rendering_device_vulkan.h | 6 +-- drivers/vulkan/vulkan_context.h | 6 +-- drivers/vulkan/vulkan_hooks.h | 6 +-- .../android/vulkan/vulkan_context_android.cpp | 6 +-- platform/ios/display_server_ios.h | 8 +--- platform/ios/os_ios.mm | 6 +-- platform/linuxbsd/x11/vulkan_context_x11.cpp | 6 +-- platform/macos/vulkan_context_macos.mm | 7 +--- platform/windows/vulkan_context_win.cpp | 7 +--- ...VKEnumStringHelper-use-godot-vulkan.patch} | 11 +++-- .../vulkan/patches/VMA-use-godot-vulkan.patch | 15 +++++++ thirdparty/vulkan/patches/VMA-use-volk.patch | 17 -------- thirdparty/vulkan/vk_enum_string_helper.h | 6 +-- thirdparty/vulkan/vk_mem_alloc.h | 9 +--- 15 files changed, 77 insertions(+), 81 deletions(-) create mode 100644 drivers/vulkan/godot_vulkan.h rename thirdparty/vulkan/patches/{VKEnumStringHelper-use-volk.patch => VKEnumStringHelper-use-godot-vulkan.patch} (68%) create mode 100644 thirdparty/vulkan/patches/VMA-use-godot-vulkan.patch delete mode 100644 thirdparty/vulkan/patches/VMA-use-volk.patch 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/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h index 2ec1574955d..9cc60731328 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -44,11 +44,7 @@ #endif #include "vk_mem_alloc.h" -#ifdef USE_VOLK -#include -#else -#include -#endif +#include "drivers/vulkan/godot_vulkan.h" class VulkanContext; diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h index 9fd2c40a06d..7a9d8ff8d11 100644 --- a/drivers/vulkan/vulkan_context.h +++ b/drivers/vulkan/vulkan_context.h @@ -40,11 +40,7 @@ #include "servers/display_server.h" #include "servers/rendering/rendering_device.h" -#ifdef USE_VOLK -#include -#else -#include -#endif +#include "drivers/vulkan/godot_vulkan.h" #include "vulkan_hooks.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/vulkan_context_android.cpp b/platform/android/vulkan/vulkan_context_android.cpp index ce4b1b79679..bf276b621f0 100644 --- a/platform/android/vulkan/vulkan_context_android.cpp +++ b/platform/android/vulkan/vulkan_context_android.cpp @@ -32,11 +32,7 @@ #include "vulkan_context_android.h" -#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 6eaa7c8edc4..50c8f66616a 100644 --- a/platform/ios/display_server_ios.h +++ b/platform/ios/display_server_ios.h @@ -40,12 +40,8 @@ #include "vulkan_context_ios.h" -#ifdef USE_VOLK -#include -#else -#include -#endif -#endif +#include "drivers/vulkan/godot_vulkan.h" +#endif // VULKAN_ENABLED #if defined(GLES3_ENABLED) #include "drivers/gles3/rasterizer_gles3.h" diff --git a/platform/ios/os_ios.mm b/platform/ios/os_ios.mm index ac2d40c6075..1c831f839b7 100644 --- a/platform/ios/os_ios.mm +++ b/platform/ios/os_ios.mm @@ -50,13 +50,9 @@ #include #if defined(VULKAN_ENABLED) +#include "drivers/vulkan/godot_vulkan.h" #include "servers/rendering/renderer_rd/renderer_compositor_rd.h" #import -#ifdef USE_VOLK -#include -#else -#include -#endif #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 454fb84859d..89412b0daca 100644 --- a/platform/macos/vulkan_context_macos.mm +++ b/platform/macos/vulkan_context_macos.mm @@ -30,11 +30,8 @@ #ifdef VULKAN_ENABLED #include "vulkan_context_macos.h" -#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 4c1e6eebe4f..6b1abe86752 100644 --- a/platform/windows/vulkan_context_win.cpp +++ b/platform/windows/vulkan_context_win.cpp @@ -31,11 +31,8 @@ #if defined(WINDOWS_ENABLED) && defined(VULKAN_ENABLED) #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 68% rename from thirdparty/vulkan/patches/VKEnumStringHelper-use-volk.patch rename to thirdparty/vulkan/patches/VKEnumStringHelper-use-godot-vulkan.patch index 849a2aa0401..cb9a0e06c88 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 65b3322c07..e8c61aaf15 100644 +index 005cc21ea8..16f1adc605 100644 --- a/thirdparty/vulkan/vk_enum_string_helper.h +++ b/thirdparty/vulkan/vk_enum_string_helper.h -@@ -37,7 +37,11 @@ +@@ -36,8 +36,10 @@ + #pragma warning( disable : 4065 ) #endif ++#ifdef __cplusplus #include -#include -+#ifdef USE_VOLK -+ #include -+#else -+ #include +#endif ++#include "drivers/vulkan/godot_vulkan.h" static inline const char* string_VkResult(VkResult input_value) diff --git a/thirdparty/vulkan/patches/VMA-use-godot-vulkan.patch b/thirdparty/vulkan/patches/VMA-use-godot-vulkan.patch new file mode 100644 index 00000000000..34d10a44003 --- /dev/null +++ b/thirdparty/vulkan/patches/VMA-use-godot-vulkan.patch @@ -0,0 +1,15 @@ +diff --git a/thirdparty/vulkan/vk_mem_alloc.h b/thirdparty/vulkan/vk_mem_alloc.h +index 6819219b00..0cde2e2172 100644 +--- a/thirdparty/vulkan/vk_mem_alloc.h ++++ b/thirdparty/vulkan/vk_mem_alloc.h +@@ -121,9 +121,7 @@ for user-defined purpose without allocating any real GPU memory. + See documentation chapter: \ref statistics. + */ + +-#ifndef VULKAN_H_ +- #include +-#endif ++#include "drivers/vulkan/godot_vulkan.h" + + #ifdef __cplusplus + extern "C" { diff --git a/thirdparty/vulkan/patches/VMA-use-volk.patch b/thirdparty/vulkan/patches/VMA-use-volk.patch deleted file mode 100644 index eebe0c1bc39..00000000000 --- a/thirdparty/vulkan/patches/VMA-use-volk.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/thirdparty/vulkan/vk_mem_alloc.h b/thirdparty/vulkan/vk_mem_alloc.h -index 44affc5ca4..d96f2dacc0 100644 ---- a/thirdparty/vulkan/vk_mem_alloc.h -+++ b/thirdparty/vulkan/vk_mem_alloc.h -@@ -127,7 +127,11 @@ extern "C" { - #endif - - #ifndef VULKAN_H_ -- #include -+ #ifdef USE_VOLK -+ #include -+ #else -+ #include -+ #endif - #endif - - // Define this macro to declare maximum supported Vulkan version in format AAABBBCCC, diff --git a/thirdparty/vulkan/vk_enum_string_helper.h b/thirdparty/vulkan/vk_enum_string_helper.h index 1869f132eb1..16f1adc6058 100644 --- a/thirdparty/vulkan/vk_enum_string_helper.h +++ b/thirdparty/vulkan/vk_enum_string_helper.h @@ -36,12 +36,10 @@ #pragma warning( disable : 4065 ) #endif +#ifdef __cplusplus #include -#ifdef USE_VOLK - #include -#else - #include #endif +#include "drivers/vulkan/godot_vulkan.h" static inline const char* string_VkResult(VkResult input_value) diff --git a/thirdparty/vulkan/vk_mem_alloc.h b/thirdparty/vulkan/vk_mem_alloc.h index ea30060649f..0cde2e21723 100644 --- a/thirdparty/vulkan/vk_mem_alloc.h +++ b/thirdparty/vulkan/vk_mem_alloc.h @@ -121,19 +121,12 @@ for user-defined purpose without allocating any real GPU memory. See documentation chapter: \ref statistics. */ +#include "drivers/vulkan/godot_vulkan.h" #ifdef __cplusplus extern "C" { #endif -#ifndef VULKAN_H_ - #ifdef USE_VOLK - #include - #else - #include - #endif -#endif - // Define this macro to declare maximum supported Vulkan version in format AAABBBCCC, // where AAA = major, BBB = minor, CCC = patch. // If you want to use version > 1.0, it still needs to be enabled via VmaAllocatorCreateInfo::vulkanApiVersion.