From cee96898f3af3627fdf3ee5e10cba7ddc8655064 Mon Sep 17 00:00:00 2001 From: Bob Ellison Date: Tue, 7 May 2024 16:36:22 -0600 Subject: [PATCH] cube: Make Volk requirement explicit See also: Cannot build DEMOS.sln https://gitlab.khronos.org/vulkan/Vulkan-SDK-Packaging/-/issues/1417 Volk requires that VK_NO_PROTOTYPES be defined before vulkan.h or vulkan.hpp is included. Currently, the various flavors of vkcube hide this definition in the cube/CMakeLists.txt file, which can confuse users who may copy the source for their own use, and may require investigation to figure out why it doesn't "just work". This change makes the #define explicit in the cube.c and cube.cpp source files, which should both be clearer and be more similar to how most applications use Volk. cube/CMakeLists.txt: - remove - vulkaninfo already had a #VK_NO_PROTOTYPES somewhere - macOS DemoViewController includes of mvk_vulkan.h are confusing Volk and don't seem to be necessary, since cube.c and cube.cpp #include vulkan.h and vulkan.hpp, respectively --- cube/CMakeLists.txt | 4 +--- cube/cube.c | 2 ++ cube/cube.cpp | 3 +++ cube/macOS/cube/DemoViewController.m | 2 -- cube/macOS/cubepp/DemoViewController.mm | 2 -- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cube/CMakeLists.txt b/cube/CMakeLists.txt index 3f4271a06..6f6943c5a 100644 --- a/cube/CMakeLists.txt +++ b/cube/CMakeLists.txt @@ -259,7 +259,6 @@ else() endif() target_include_directories(vkcube PRIVATE .) -target_compile_definitions(vkcube PRIVATE VK_NO_PROTOTYPES) if (ANDROID) install(TARGETS vkcube DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -307,7 +306,6 @@ else() target_link_libraries(vkcubepp Vulkan::Headers volk::volk_headers) endif() target_include_directories(vkcubepp PRIVATE .) -target_compile_definitions(vkcubepp PRIVATE VK_NO_PROTOTYPES) if(APPLE) install( @@ -351,7 +349,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "Linux|BSD") Threads::Threads PkgConfig::WAYLAND_CLIENT ) - target_compile_definitions(vkcube-wayland PRIVATE VK_USE_PLATFORM_WAYLAND_KHR VK_NO_PROTOTYPES) + target_compile_definitions(vkcube-wayland PRIVATE VK_USE_PLATFORM_WAYLAND_KHR) include(CheckLibraryExists) CHECK_LIBRARY_EXISTS("rt" clock_gettime "" NEED_RT) if (NEED_RT) diff --git a/cube/cube.c b/cube/cube.c index c473bbfd8..b965964e9 100644 --- a/cube/cube.c +++ b/cube/cube.c @@ -49,6 +49,8 @@ #define APP_NAME_STR_LEN 80 #endif // _WIN32 +// Volk requires VK_NO_PROTOTYPES before including vulkan.h +#define VK_NO_PROTOTYPES #include #define VOLK_IMPLEMENTATION #include "volk.h" diff --git a/cube/cube.cpp b/cube/cube.cpp index edefbf091..ccf0ec80c 100644 --- a/cube/cube.cpp +++ b/cube/cube.cpp @@ -41,6 +41,9 @@ #define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1 #define VULKAN_HPP_NO_EXCEPTIONS #define VULKAN_HPP_TYPESAFE_CONVERSION 1 + +// Volk requires VK_NO_PROTOTYPES before including vulkan.hpp +#define VK_NO_PROTOTYPES #include #define VOLK_IMPLEMENTATION diff --git a/cube/macOS/cube/DemoViewController.m b/cube/macOS/cube/DemoViewController.m index 49d3f01b0..d21585216 100644 --- a/cube/macOS/cube/DemoViewController.m +++ b/cube/macOS/cube/DemoViewController.m @@ -19,8 +19,6 @@ #import "DemoViewController.h" #import -#include - #include "cube.c" #pragma mark - diff --git a/cube/macOS/cubepp/DemoViewController.mm b/cube/macOS/cubepp/DemoViewController.mm index 3313a11d7..2635b588e 100644 --- a/cube/macOS/cubepp/DemoViewController.mm +++ b/cube/macOS/cubepp/DemoViewController.mm @@ -19,8 +19,6 @@ #import "DemoViewController.h" #import -#include - #include "cube.cpp" #pragma mark -