How is the size of a surface determined in Vulkan?


I'm following the Vulkan Tutorial and the section Window Surface says that on Windows a VkSurfaceKHR object is created using the following code:

VkWin32SurfaceCreateInfoKHR createInfo = {};
createInfo.hwnd = glfwGetWin32Window(window);
createInfo.hinstance = GetModuleHandle(nullptr);

if (vkCreateWin32SurfaceKHR(instance, &createInfo, nullptr, &surface) != VK_SUCCESS) {
    throw std::runtime_error("failed to create window surface!");

But we never specify the extents of the surface in the createInfo object.

However calling the vkGetPhysicalDeviceSurfaceCapabilitiesKHR function returns a VkSurfaceCapabilitiesKHR object which has a currentExtent field which according to the documentation is

the current width and height of the surface, or the special value (0xFFFFFFFF, 0xFFFFFFFF) indicating that the surface size will be determined by the extent of a swapchain targeting the surface.

So in the special case that currentExtent equals (0xFFFFFFFF, 0xFFFFFFFF) we know that the size of the surface is determined by the swapchain targeting the surface, but in all other cases it seems that the surface already has a size originating from somewhere else and we are expected to match the extents of the swapchain to that size.

So where does the size of the surface come from when it's not being determined by the swapchain?

asked on Stack Overflow Jan 6, 2020 by David DiGioia

1 Answer


On Windows, the initial extents of the surface are equal to the width and height values you set when creating the window (minus window borders, menus, etc.).

The extents value returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR also updates automatically when the window is resized by the user (on Windows).

It is also important to note that on different platforms, max, min, and current extents behave differently. On Windows, the output surface must always be equal to the paintable window size, so they will all be equal.

answered on Stack Overflow Jan 6, 2020 by Aaron Hull

User contributions licensed under CC BY-SA 3.0