Skip to content

Commit a0997fa

Browse files
committed
Remove Vulkan SDK build dependency by bundling Vulkan headers
The Vulkan backend already uses VK_NO_PROTOTYPES + dynamic dispatch (vulkan.hpp dispatcher bootstrapped from SDL), so the link to Vulkan::Vulkan was unused. Replace find_package(Vulkan) with bundled Vulkan-Headers (v1.4.309) for both code and imgui targets. Make imgui compile with VK_NO_PROTOTYPES (PUBLIC) and load its Vulkan function pointers via ImGui_ImplVulkan_LoadFunctions() at init time.
1 parent 27c8e58 commit a0997fa

47 files changed

Lines changed: 333913 additions & 13 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

code/CMakeLists.txt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,8 @@ if (FSO_BUILD_WITH_OPENGL)
113113
target_compile_definitions(code PUBLIC WITH_OPENGL)
114114
endif()
115115
if (FSO_BUILD_WITH_VULKAN)
116-
find_package(Vulkan REQUIRED)
117-
if (Vulkan_FOUND)
118-
target_compile_definitions(code PUBLIC WITH_VULKAN)
119-
target_link_libraries(code PRIVATE Vulkan::Vulkan)
120-
121-
target_compile_definitions(code PUBLIC WITH_VULKAN VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 VK_NO_PROTOTYPES)
122-
else()
123-
message(WARNING "FSO_BUILD_WITH_VULKAN was set, but the package was unable to be found. Forcing OFF.")
124-
set(FSO_BUILD_WITH_VULKAN OFF CACHE BOOL "Enable compilation of the Vulkan renderer" FORCE)
125-
endif()
116+
target_compile_definitions(code PUBLIC WITH_VULKAN VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 VK_NO_PROTOTYPES)
117+
target_link_libraries(code PUBLIC VulkanHeaders)
126118
endif()
127119

128120
include(shaders.cmake)

code/graphics/vulkan/VulkanRenderer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,13 @@ void VulkanRenderer::initImGui()
15011501
{
15021502
createImGuiDescriptorPool();
15031503

1504+
// Load Vulkan function pointers for imgui (required with VK_NO_PROTOTYPES)
1505+
auto vkInstance = static_cast<VkInstance>(*m_vkInstance);
1506+
ImGui_ImplVulkan_LoadFunctions([](const char* function_name, void* user_data) -> PFN_vkVoidFunction {
1507+
return VULKAN_HPP_DEFAULT_DISPATCHER.vkGetInstanceProcAddr(
1508+
static_cast<VkInstance>(user_data), function_name);
1509+
}, vkInstance);
1510+
15041511
ImGui_ImplVulkan_InitInfo initInfo = {};
15051512
initInfo.Instance = static_cast<VkInstance>(*m_vkInstance);
15061513
initInfo.PhysicalDevice = static_cast<VkPhysicalDevice>(m_physicalDevice);

lib/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ include(antlr4.cmake)
4545

4646
include(vulkan.cmake)
4747

48+
if (FSO_BUILD_WITH_VULKAN)
49+
add_subdirectory(vulkan-headers)
50+
endif()
51+
4852
add_subdirectory(mdns)
4953

5054
add_subdirectory(accidental-noise)

lib/imgui/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ TARGET_LINK_LIBRARIES(imgui PUBLIC sdl2)
3939
target_link_libraries(imgui PUBLIC compiler)
4040

4141
if (FSO_BUILD_WITH_VULKAN)
42-
find_package(Vulkan REQUIRED)
43-
target_compile_definitions(imgui INTERFACE VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 VK_NO_PROTOTYPES)
44-
target_link_libraries(imgui PRIVATE Vulkan::Vulkan)
42+
target_compile_definitions(imgui PUBLIC VK_NO_PROTOTYPES)
43+
target_compile_definitions(imgui INTERFACE VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1)
44+
target_link_libraries(imgui PUBLIC VulkanHeaders)
4545
endif()

lib/vulkan-headers/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_library(VulkanHeaders INTERFACE)
2+
target_include_directories(VulkanHeaders SYSTEM INTERFACE
3+
"${CMAKE_CURRENT_SOURCE_DIR}/include"
4+
)

0 commit comments

Comments
 (0)