Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend platform support for WSI without the need to include windowing API #195

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
112 changes: 94 additions & 18 deletions volk.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,107 @@
# define VK_NO_PROTOTYPES
#endif


/* When VK_USE_PLATFORM_XYZ is defined, instead of including vulkan.h directly, we include individual parts of the SDK
* This is necessary to avoid including platform-specific headers which may be very heavy -
* it takes 200ms to parse windows.h without WIN32_LEAN_AND_MEAN and 100ms to parse with it.
* The WSI only needs a few symbols that are straightforward to redefine ourselves.
* Currently supported platforms:
* VK_USE_PLATFORM_FUCHSIA
* VK_USE_PLATFORM_WIN32_KHR
* VK_USE_PLATFORM_XLIB_KHR
* VK_USE_PLATFORM_XCB_KHR
* VK_USE_PLATFORM_DIRECTFB_EXT
* VK_USE_PLATFORM_XLIB_XRANDR_EXT
* VK_USE_PLATFORM_GGP
* VK_USE_PLATFORM_SCREEN_QNX
*
* Nothing needs to be done for the following platforms as they don't depend on platform-specific headers:
* VK_USE_PLATFORM_MACOS_MVK
* VK_USE_PLATFORM_METAL_EXT
* VK_USE_PLATFORM_VI_NN
* VK_USE_PLATFORM_WAYLAND_KHR
*/

#ifndef VULKAN_H_
# include <vulkan/vulkan_core.h>

# ifdef VOLK_VULKAN_H_PATH
# include VOLK_VULKAN_H_PATH
# elif defined(VK_USE_PLATFORM_WIN32_KHR)
# include <vulkan/vk_platform.h>
# include <vulkan/vulkan_core.h>
# else
# if defined(VK_USE_PLATFORM_FUCHSIA)
// If someone knows what the include guard for <lib/zx/handle.h> is, please add a guard arround this
typedef uint32_t zx_handle_t;

/* When VK_USE_PLATFORM_WIN32_KHR is defined, instead of including vulkan.h directly, we include individual parts of the SDK
* This is necessary to avoid including <windows.h> which is very heavy - it takes 200ms to parse without WIN32_LEAN_AND_MEAN
* and 100ms to parse with it. vulkan_win32.h only needs a few symbols that are easy to redefine ourselves.
*/
typedef unsigned long DWORD;
typedef const wchar_t* LPCWSTR;
typedef void* HANDLE;
typedef struct HINSTANCE__* HINSTANCE;
typedef struct HWND__* HWND;
typedef struct HMONITOR__* HMONITOR;
typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
# include <vulkan/vulkan_fuchsia.h>
# undef VK_USE_PLATFORM_FUCHSIA
# endif
# if defined(VK_USE_PLATFORM_WIN32_KHR)
# if !defined(WINDOWS_H)
typedef unsigned long DWORD;
typedef const wchar_t* LPCWSTR;
typedef void* HANDLE;
typedef struct HINSTANCE__* HINSTANCE;
typedef struct HWND__* HWND;
typedef struct HMONITOR__* HMONITOR;
typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
# endif

# include <vulkan/vulkan_win32.h>
# include <vulkan/vulkan_win32.h>
# undef VK_USE_PLATFORM_WIN32_KHR
# endif
# if defined(VK_USE_PLATFORM_XLIB_KHR)
// This is not 1:1 what Xlib uses, but it's close enough for most purposes.
# if !defined(X_H)
// This is an include guard for the XLIB_XRANDR platform.
# define VOLK_VULKAN_H_DEFINE_XLIB_STRUCTURES
typedef struct Display Display;
typedef uint32_t Window;
typedef uint32_t VisualID;
# endif

# ifdef VK_ENABLE_BETA_EXTENSIONS
# include <vulkan/vulkan_beta.h>
# include <vulkan/vulkan_xlib.h>
# undef VK_USE_PLATFORM_XLIB_KHR
# endif
# if defined(VK_USE_PLATFORM_XCB_KHR)
# if !defined(__XCB_H__)
typedef struct xcb_connection_t xcb_connection_t;
typedef uint32_t xcb_window_t;
typedef uint32_t xcb_visualid_t;
# endif

# include <vulkan/vulkan_xcb.h>
# undef VK_USE_PLATFORM_XCB_KHR
# endif
# if defined(VK_USE_PLATFORM_DIRECTFB_EXT)
typedef struct IDirectFB IDirectFB;
typedef struct IDirectFBSurface IDirectFBSurface;

# include <vulkan/vulkan_directfb.h>
# undef VK_USE_PLATFORM_DIRECTFB_EXT
# endif
# if defined(VK_USE_PLATFORM_XLIB_XRANDR_EXT)
# if !defined(X_H) && !defined(VOLK_VULKAN_H_DEFINE_XLIB_STRUCTURES)
typedef struct Display Display;
# endif
# if !defined(_RANDRSTR_H_)
typedef uint32_t RROutput;
# endif

# include <vulkan/vulkan_xlib_xrandr.h>
# undef VK_USE_PLATFORM_XLIB_XRANDR_EXT
# endif
# if defined(VK_USE_PLATFORM_GGP)
typedef uint32_t GgpStreamDescriptor;
typedef uint64_t GgpFrameToken;

# include <vulkan/vulkan_ggp.h>
# undef VK_USE_PLATFORM_GGP
# endif
# if defined(VK_USE_PLATFORM_SCREEN_QNX)
# include <vulkan/vulkan_screen.h>
# undef VK_USE_PLATFORM_SCREEN_QNX
# endif
# else
# include <vulkan/vulkan.h>
# endif
#endif
Expand Down