Skip to content

Commit bdf0134

Browse files
authored
Merge pull request #225 from zeux/xlibh
Remove dependency on Xlib.h
2 parents 67a102e + ca28c7f commit bdf0134

File tree

1 file changed

+103
-21
lines changed

1 file changed

+103
-21
lines changed

volk.h

+103-21
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,9 @@
2525
#ifndef VULKAN_H_
2626
# ifdef VOLK_VULKAN_H_PATH
2727
# include VOLK_VULKAN_H_PATH
28-
# elif defined(VK_USE_PLATFORM_WIN32_KHR)
28+
# else /* Platform headers included below */
2929
# include <vulkan/vk_platform.h>
3030
# include <vulkan/vulkan_core.h>
31-
32-
/* When VK_USE_PLATFORM_WIN32_KHR is defined, instead of including vulkan.h directly, we include individual parts of the SDK
33-
* This is necessary to avoid including <windows.h> which is very heavy - it takes 200ms to parse without WIN32_LEAN_AND_MEAN
34-
* and 100ms to parse with it. vulkan_win32.h only needs a few symbols that are easy to redefine ourselves.
35-
*/
36-
typedef unsigned long DWORD;
37-
typedef const wchar_t* LPCWSTR;
38-
typedef void* HANDLE;
39-
typedef struct HINSTANCE__* HINSTANCE;
40-
typedef struct HWND__* HWND;
41-
typedef struct HMONITOR__* HMONITOR;
42-
typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
43-
44-
# include <vulkan/vulkan_win32.h>
45-
46-
# ifdef VK_ENABLE_BETA_EXTENSIONS
47-
# include <vulkan/vulkan_beta.h>
48-
# endif
49-
# else
50-
# include <vulkan/vulkan.h>
5131
# endif
5232
#endif
5333

@@ -124,6 +104,104 @@ VkDevice volkGetLoadedDevice(void);
124104
*/
125105
void volkLoadDeviceTable(struct VolkDeviceTable* table, VkDevice device);
126106

107+
#ifdef __cplusplus
108+
}
109+
#endif
110+
111+
/* Instead of directly including vulkan.h, we include platform-specific parts of the SDK manually
112+
* This is necessary to avoid including platform headers in some cases (which vulkan.h does unconditionally)
113+
* and replace them with forward declarations, which makes build times faster and avoids macro conflicts.
114+
*
115+
* Note that we only replace platform-specific headers when the headers are known to be problematic: very large
116+
* or slow to compile (Windows), or introducing unprefixed macros which can cause conflicts (Windows, Xlib).
117+
*/
118+
#if !defined(VULKAN_H_) && !defined(VOLK_VULKAN_H_PATH)
119+
120+
#ifdef VK_USE_PLATFORM_ANDROID_KHR
121+
#include <vulkan/vulkan_android.h>
122+
#endif
123+
124+
#ifdef VK_USE_PLATFORM_FUCHSIA
125+
#include <zircon/types.h>
126+
#include <vulkan/vulkan_fuchsia.h>
127+
#endif
128+
129+
#ifdef VK_USE_PLATFORM_IOS_MVK
130+
#include <vulkan/vulkan_ios.h>
131+
#endif
132+
133+
#ifdef VK_USE_PLATFORM_MACOS_MVK
134+
#include <vulkan/vulkan_macos.h>
135+
#endif
136+
137+
#ifdef VK_USE_PLATFORM_METAL_EXT
138+
#include <vulkan/vulkan_metal.h>
139+
#endif
140+
141+
#ifdef VK_USE_PLATFORM_VI_NN
142+
#include <vulkan/vulkan_vi.h>
143+
#endif
144+
145+
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
146+
#include <vulkan/vulkan_wayland.h>
147+
#endif
148+
149+
#ifdef VK_USE_PLATFORM_WIN32_KHR
150+
typedef unsigned long DWORD;
151+
typedef const wchar_t* LPCWSTR;
152+
typedef void* HANDLE;
153+
typedef struct HINSTANCE__* HINSTANCE;
154+
typedef struct HWND__* HWND;
155+
typedef struct HMONITOR__* HMONITOR;
156+
typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
157+
#include <vulkan/vulkan_win32.h>
158+
#endif
159+
160+
#ifdef VK_USE_PLATFORM_XCB_KHR
161+
#include <xcb/xcb.h>
162+
#include <vulkan/vulkan_xcb.h>
163+
#endif
164+
165+
#ifdef VK_USE_PLATFORM_XLIB_KHR
166+
typedef struct _XDisplay Display;
167+
typedef unsigned long Window;
168+
typedef unsigned long VisualID;
169+
#include <vulkan/vulkan_xlib.h>
170+
#endif
171+
172+
#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
173+
#include <directfb.h>
174+
#include <vulkan/vulkan_directfb.h>
175+
#endif
176+
177+
#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
178+
typedef struct _XDisplay Display;
179+
typedef unsigned long RROutput;
180+
#include <vulkan/vulkan_xlib_xrandr.h>
181+
#endif
182+
183+
#ifdef VK_USE_PLATFORM_GGP
184+
#include <ggp_c/vulkan_types.h>
185+
#include <vulkan/vulkan_ggp.h>
186+
#endif
187+
188+
#ifdef VK_USE_PLATFORM_SCREEN_QNX
189+
#include <screen/screen.h>
190+
#include <vulkan/vulkan_screen.h>
191+
#endif
192+
193+
#ifdef VK_USE_PLATFORM_SCI
194+
#include <nvscisync.h>
195+
#include <nvscibuf.h>
196+
#include <vulkan/vulkan_sci.h>
197+
#endif
198+
199+
#ifdef VK_ENABLE_BETA_EXTENSIONS
200+
#include <vulkan/vulkan_beta.h>
201+
#endif
202+
203+
#endif
204+
127205
/**
128206
* Device-specific function pointer table
129207
*/
@@ -1055,6 +1133,10 @@ struct VolkDeviceTable
10551133
/* VOLK_GENERATE_DEVICE_TABLE */
10561134
};
10571135

1136+
#ifdef __cplusplus
1137+
extern "C" {
1138+
#endif
1139+
10581140
/* VOLK_GENERATE_PROTOTYPES_H */
10591141
#if defined(VK_VERSION_1_0)
10601142
extern PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers;

0 commit comments

Comments
 (0)