5

I'm attempting to write a simple vulkan based application, but when trying to add the surface extension to the list of enabled extensions, like so:

    enabledExtensions.push_back( VK_KHR_SURFACE_EXTENSION_NAME );
#if defined (_WIN32)
    enabledExtensions.push_back( VK_KHR_WIN32_SURFACE_EXTENSION_NAME );
#else
    enabledExtensions.push_back( VK_KHR_XCB_SURFACE_EXTENSION_NAME );
#endif

Visual studio complains that VK_KHR_WIN32_SURFACE_EXTENSION_NAMEis undefined.

When I right click it and go to definition, it opens vulkan.h. Upon inspection of VK_USE_PLATFORM_WIN32_KHR I find this to be also undefined, which prevents the definition of VK_KHR_WIN32_SURFACE_EXTENSION_NAME. Could someone explain how to fix this?

Ian Young
  • 1,712
  • 1
  • 16
  • 33

2 Answers2

13

As it turns out, I was missing some preprocessor directives in the project settings:

VK_PROTOTYPES
VK_USE_PLATFORM_WIN32_KHR

I hope this info helps out anyone who has the same problem.

Ian Young
  • 1,712
  • 1
  • 16
  • 33
  • 1
    There is no VK_PROTOTYPES, but VK_NO_PROTOTYPES, with opposite effect. In another words, to solve this issue you only need VK_USE_PLATFORM_WIN32_KHR – Alex Byrth Jun 20 '16 at 13:26
  • 1
    In my case, in order to simply expose `VK_KHR_WIN32_SURFACE_EXTENSION_NAME`, all I needed was to add the `VK_USE_PLATFORM_WIN32_KHR` preprocessor define. Great answer, great followup! – Aaron Hull Aug 28 '19 at 06:35
1

This seems to be a common problem, currently you can fix this by adding the specific header

#if defined (_WIN32)
    #include <vulkan/vulkan_win32.h>
#elif defined(__linux__)
    #include <vulkan/vulkan_xcb.h>
#elif defined(__ANDROID__)
    #include <vulkan/vulkan_android.h>
#endif
Ulises
  • 539
  • 3
  • 9