21 #include "../SDL_internal.h"
38 return "VK_NOT_READY";
42 return "VK_EVENT_SET";
44 return "VK_EVENT_RESET";
46 return "VK_INCOMPLETE";
48 return "VK_ERROR_OUT_OF_HOST_MEMORY";
50 return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
52 return "VK_ERROR_INITIALIZATION_FAILED";
54 return "VK_ERROR_DEVICE_LOST";
56 return "VK_ERROR_MEMORY_MAP_FAILED";
58 return "VK_ERROR_LAYER_NOT_PRESENT";
60 return "VK_ERROR_EXTENSION_NOT_PRESENT";
62 return "VK_ERROR_FEATURE_NOT_PRESENT";
64 return "VK_ERROR_INCOMPATIBLE_DRIVER";
66 return "VK_ERROR_TOO_MANY_OBJECTS";
68 return "VK_ERROR_FORMAT_NOT_SUPPORTED";
70 return "VK_ERROR_FRAGMENTED_POOL";
72 return "VK_ERROR_SURFACE_LOST_KHR";
74 return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
76 return "VK_SUBOPTIMAL_KHR";
78 return "VK_ERROR_OUT_OF_DATE_KHR";
80 return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
82 return "VK_ERROR_VALIDATION_FAILED_EXT";
84 return "VK_ERROR_OUT_OF_POOL_MEMORY_KHR";
86 return "VK_ERROR_INVALID_SHADER_NV";
92 return "VK_ERROR_<Unknown>";
93 return "VK_<Unknown>";
109 "You probably don't have a working Vulkan driver installed. %s %s %s(%d)",
110 "Getting Vulkan extensions failed:",
111 "vkEnumerateInstanceExtensionProperties returned",
112 SDL_Vulkan_GetResultString(
result),
119 "Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned "
121 SDL_Vulkan_GetResultString(
result),
142 "Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned "
144 SDL_Vulkan_GetResultString(
result),
149 *extensionCount =
count;
153 SDL_bool SDL_Vulkan_GetInstanceExtensions_Helper(
unsigned *userCount,
154 const char **userNames,
156 const char *
const *
names)
161 if (*userCount < nameCount) {
162 SDL_SetError(
"Output array for SDL_Vulkan_GetInstanceExtensions needs to be at least %d big", nameCount);
165 for (
i = 0;
i < nameCount;
i++) {
169 *userCount = nameCount;
181 SDL_bool SDL_Vulkan_Display_CreateSurface(
void *vkGetInstanceProcAddr_,
187 #define VULKAN_INSTANCE_FUNCTION(name) \
188 PFN_##name name = (PFN_##name)vkGetInstanceProcAddr((VkInstance)instance, #name)
196 #undef VULKAN_INSTANCE_FUNCTION
200 VkPhysicalDevice *physicalDevices =
NULL;
202 const char *chosenDisplayId;
214 " extension is not enabled in the Vulkan instance.");
220 displayId =
SDL_atoi(chosenDisplayId);
228 SDL_SetError(
"Could not enumerate Vulkan physical devices");
231 if(physicalDeviceCount == 0)
236 physicalDevices =
SDL_malloc(
sizeof(VkPhysicalDevice) * physicalDeviceCount);
250 for(physicalDeviceIndex = 0; physicalDeviceIndex < physicalDeviceCount;
251 physicalDeviceIndex++)
253 VkPhysicalDevice physicalDevice = physicalDevices[physicalDeviceIndex];
254 uint32_t displayPropertiesCount = 0;
256 uint32_t displayModePropertiesCount = 0;
258 int bestMatchIndex = -1;
261 uint32_t displayPlanePropertiesCount = 0;
263 VkDisplayKHR display;
277 physicalDeviceIndex, displayPropertiesCount);
279 if ( (displayId < 0) || (((
uint32_t) displayId) >= displayPropertiesCount) )
282 displayId -= displayPropertiesCount;
287 if(!displayProperties)
297 SDL_SetError(
"Error enumerating physical device displays");
301 display = displayProperties[displayId].
display;
304 displayProperties[displayId].displayName, extent.
width, extent.
height);
307 displayProperties =
NULL;
320 if(!displayModeProperties)
335 for (
i = 0;
i < displayModePropertiesCount; ++
i)
337 if (displayModeProperties[
i].parameters.visibleRegion.width == extent.
width &&
338 displayModeProperties[
i].parameters.visibleRegion.height == extent.
height &&
339 displayModeProperties[
i].parameters.refreshRate > refreshRate)
345 if (bestMatchIndex < 0)
355 displayModeProperties[bestMatchIndex].parameters.visibleRegion.width,
356 displayModeProperties[bestMatchIndex].parameters.visibleRegion.height,
360 displayModeProperties =
NULL;
373 if(!displayPlaneProperties)
383 SDL_SetError(
"Error enumerating display plane properties");
388 for (
i = 0;
i < displayPlanePropertiesCount; ++
i)
390 uint32_t planeSupportedDisplaysCount = 0;
391 VkDisplayKHR *planeSupportedDisplays =
NULL;
407 planeSupportedDisplays =
SDL_malloc(
sizeof(VkDisplayKHR) * planeSupportedDisplaysCount);
408 if(!planeSupportedDisplays)
419 SDL_SetError(
"Error enumerating supported displays, or no supported displays");
425 for (
j = 0;
j < planeSupportedDisplaysCount && planeSupportedDisplays[
j] != display; ++
j)
429 planeSupportedDisplays =
NULL;
431 if (
j == planeSupportedDisplaysCount)
440 SDL_SetError(
"Error getting display plane capabilities");
460 SDL_SetError(
"No plane supports the selected resolution");
468 displayPlaneProperties =
NULL;
486 physicalDevices =
NULL;
488 if (physicalDeviceIndex == physicalDeviceCount)
490 SDL_SetError(
"No usable displays found or requested display out of range");
502 SDL_SetError(
"vkCreateDisplayPlaneSurfaceKHR failed: %s",
503 SDL_Vulkan_GetResultString(
result));