Reputation: 68618
The function vkGetPhysicalDeviceSurfaceFormatsKHR
returns a list of supported VkSurfaceFormatKHRs
for a given physical device and surface:
struct VkSurfaceFormatKHR {
VkFormat format;
VkColorSpaceKHR colorSpace;
};
When creating a swapchain for a surface you must select the required VkFormat
and VkColorSpaceKHR
in VkSwapchainCreateInfoKHR
...
struct VkSwapchainCreateInfoKHR {
/* ... */
VkFormat imageFormat;
VkColorSpaceKHR imageColorSpace;
/* ... */
};
and these must match one of the VkSurfaceFormatKHRs
.
What is a example implementation of a function:
VkSurfaceFormatKHR SelectSurfaceFormat(std::vector<VkSurfaceFormatKHR>)
That selects a VkSurfaceFormatKHR
from the multiple VkSurfaceFormatKHRs
returned by vkGetPhysicalDeviceSurfaceFormatsKHR
in a way that is reasonably general-purpose?
Upvotes: 1
Views: 2594
Reputation: 442
You should exercise the same discretion when choosing a format that you would when choosing a physical device.
If you have a preference for color precision, like if you had a preference for physical device capabilities, I suggest building a list of your preferred formats and running a typical for loop to check if they are supported in order.
If you don't have a preference in any way, you might model your app after the LunarG Vulkan Sample project which asserts that size of surfaceFormats > 0
and defaults to surfaceFormats[0].
The sample also handles the case that surfaceFormats[0] == VK_FORMAT_UNDEFINED
, but as mentioned in the comments, this is no longer a valid value and may be omitted.
Upvotes: 1