OpenGL & Vulkan windowsSDL 3.2

SDL_Vulkan_CreateSurface

Creates the VkSurfaceKHR for an SDL window: the bridge between Vulkan and the window.

Signature

bool SDL_Vulkan_CreateSurface(SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface);

How it works

The surface is what the swapchain presents to. Each platform creates it with a different Vulkan function; SDL calls the right one. The window needs SDL_WINDOW_VULKAN, and the instance must have the extensions from SDL_Vulkan_GetInstanceExtensions.

Destroy it before the instance with SDL_Vulkan_DestroySurface (or vkDestroySurfaceKHR).

Parameters

windowSDL_Window *

A window created with SDL_WINDOW_VULKAN.

instanceVkInstance

Your Vulkan instance.

allocatorconst struct VkAllocationCallbacks *

Custom allocator, usually NULL.

surfaceVkSurfaceKHR *

Receives the surface.

Return value

true on success, false on failure.

Example

example.cpp
1VkSurfaceKHR surface;
2if (!SDL_Vulkan_CreateSurface(window, instance, nullptr, &surface)) {
3    SDL_Log("surface: %s", SDL_GetError());
4    return 1;
5}
6// ... at shutdown, before vkDestroyInstance:
7SDL_Vulkan_DestroySurface(instance, surface, nullptr);
Official SDL wiki