gardenThe bridge between the window and Vulkan
Vulkan surface
The concept
Vulkan is an agnostic API: it does not know what a "window" is in Windows,
macOS, or Linux. To draw on the screen, we need to create a bridge between the
windowing system (managed here by GLFW, see Window & Native surface) and Vulkan. This bridge
is called the surface (VkSurfaceKHR).
The surface is just an abstract connection to the window — it does not hold any actual pixels. It is created right after the Vulkan instance, and the Vulkan physical device is then checked against it (a GPU must be able to present to this surface, see Vulkan queue families).
In game engine
This step is handled by glfwCreateWindowSurface, which abstracts away the
OS-specific complexity:
// cpp
bool VulkanContext::createSurface()
{
VkSurfaceKHR surface;
if (glfwCreateWindowSurface(*d_instance,
d_platform_p->window(),
nullptr,
&surface) != VK_SUCCESS) {
std::cerr << "Failed to create window surface." << std::endl;
return false;
}
d_surface = vk::raii::SurfaceKHR(d_instance, surface);
return true;
}Linked references 5
notes that point at this one
Vulkan Swapchainvulkan
Once we have a Vulkan logical device and a Vulkan surface, we have the infrastructure to draw — but no canvas yet.
Vulkan logical devicevulkan
However, we still have a major problem: where do we put these rendered images so the user can see them? The Vulkan surface we created earlier is just an abstract connect…
Vulkan physical devicevulkan
Even though the instance handles the Vulkan surface creation, the physical device needs specific extensions to interact with that surface and manage memory.
Vulkan queue familiesvulkan
Presentation: send the rendered images to the Vulkan surface (the screen).
Architecturegamegine
Vulkan surface — the bridge between the window and Vulkan.