vulkan: SDL_Vulkan_GetInstanceExtensions should accept a NULL window.
authorJeremy Ong <jeremycong@gmail.com>
Fri, 24 Aug 2018 09:49:48 -0400
changeset 121515b9895d82ebe
parent 12150 f958f3c2e006
child 12152 cb129c06aa86
vulkan: SDL_Vulkan_GetInstanceExtensions should accept a NULL window.

Fixes Bugzilla #4235.
include/SDL_vulkan.h
src/video/SDL_video.c
test/testvulkan.c
     1.1 --- a/include/SDL_vulkan.h	Thu Aug 23 14:05:25 2018 -0700
     1.2 +++ b/include/SDL_vulkan.h	Fri Aug 24 09:49:48 2018 -0400
     1.3 @@ -135,7 +135,7 @@
     1.4   *  \brief Get the names of the Vulkan instance extensions needed to create
     1.5   *         a surface with \c SDL_Vulkan_CreateSurface().
     1.6   *
     1.7 - *  \param [in]     window Window for which the required Vulkan instance
     1.8 + *  \param [in]     \c NULL or window Window for which the required Vulkan instance
     1.9   *                  extensions should be retrieved
    1.10   *  \param [in,out] count pointer to an \c unsigned related to the number of
    1.11   *                  required Vulkan instance extensions
    1.12 @@ -153,6 +153,10 @@
    1.13   *  is smaller than the number of required extensions, \c SDL_FALSE will be
    1.14   *  returned instead of \c SDL_TRUE, to indicate that not all the required
    1.15   *  extensions were returned.
    1.16 + * 
    1.17 + *  \note If \c window is not NULL, it will be checked against its creation
    1.18 + *        flags to ensure that the Vulkan flag is present. This parameter
    1.19 + *        will be removed in a future major release.
    1.20   *
    1.21   *  \note The returned list of extensions will contain \c VK_KHR_surface
    1.22   *        and zero or more platform specific extensions
    1.23 @@ -160,12 +164,13 @@
    1.24   *  \note The extension names queried here must be enabled when calling
    1.25   *        VkCreateInstance, otherwise surface creation will fail.
    1.26   *
    1.27 - *  \note \c window should have been created with the \c SDL_WINDOW_VULKAN flag.
    1.28 + *  \note \c window should have been created with the \c SDL_WINDOW_VULKAN flag
    1.29 + *        or be \c NULL
    1.30   *
    1.31   *  \code
    1.32   *  unsigned int count;
    1.33   *  // get count of required extensions
    1.34 - *  if(!SDL_Vulkan_GetInstanceExtensions(window, &count, NULL))
    1.35 + *  if(!SDL_Vulkan_GetInstanceExtensions(NULL, &count, NULL))
    1.36   *      handle_error();
    1.37   *
    1.38   *  static const char *const additionalExtensions[] =
    1.39 @@ -179,7 +184,7 @@
    1.40   *      handle_error();
    1.41   *
    1.42   *  // get names of required extensions
    1.43 - *  if(!SDL_Vulkan_GetInstanceExtensions(window, &count, names))
    1.44 + *  if(!SDL_Vulkan_GetInstanceExtensions(NULL, &count, names))
    1.45   *      handle_error();
    1.46   *
    1.47   *  // copy additional extensions after required extensions
     2.1 --- a/src/video/SDL_video.c	Thu Aug 23 14:05:25 2018 -0700
     2.2 +++ b/src/video/SDL_video.c	Fri Aug 24 09:49:48 2018 -0400
     2.3 @@ -4103,11 +4103,14 @@
     2.4  
     2.5  SDL_bool SDL_Vulkan_GetInstanceExtensions(SDL_Window *window, unsigned *count, const char **names)
     2.6  {
     2.7 -    CHECK_WINDOW_MAGIC(window, SDL_FALSE);
     2.8 -
     2.9 -    if (!(window->flags & SDL_WINDOW_VULKAN)) {
    2.10 -        SDL_SetError(NOT_A_VULKAN_WINDOW);
    2.11 -        return SDL_FALSE;
    2.12 +    if (window) {
    2.13 +        CHECK_WINDOW_MAGIC(window, SDL_FALSE);
    2.14 +
    2.15 +        if (!(window->flags & SDL_WINDOW_VULKAN))
    2.16 +        {
    2.17 +            SDL_SetError(NOT_A_VULKAN_WINDOW);
    2.18 +            return SDL_FALSE;
    2.19 +        }
    2.20      }
    2.21  
    2.22      if (!count) {
     3.1 --- a/test/testvulkan.c	Thu Aug 23 14:05:25 2018 -0700
     3.2 +++ b/test/testvulkan.c	Fri Aug 24 09:49:48 2018 -0400
     3.3 @@ -255,7 +255,7 @@
     3.4      appInfo.apiVersion = VK_API_VERSION_1_0;
     3.5      instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
     3.6      instanceCreateInfo.pApplicationInfo = &appInfo;
     3.7 -    if(!SDL_Vulkan_GetInstanceExtensions(state->windows[0], &extensionCount, NULL))
     3.8 +    if(!SDL_Vulkan_GetInstanceExtensions(NULL, &extensionCount, NULL))
     3.9      {
    3.10          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
    3.11                       "SDL_Vulkan_GetInstanceExtensions(): %s\n",
    3.12 @@ -268,7 +268,7 @@
    3.13          SDL_OutOfMemory();
    3.14          quit(2);
    3.15      }
    3.16 -    if(!SDL_Vulkan_GetInstanceExtensions(state->windows[0], &extensionCount, extensions))
    3.17 +    if(!SDL_Vulkan_GetInstanceExtensions(NULL, &extensionCount, extensions))
    3.18      {
    3.19          SDL_free((void*)extensions);
    3.20          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,