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;
153SDL_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;
181SDL_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));
#define SDL_OutOfMemory()
GLuint GLuint GLsizei count
#define SDL_arraysize(array)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
VkDisplayModeParametersKHR parameters
VkDisplayModeKHR displayMode
VkDisplayPlaneAlphaFlagsKHR supportedAlpha
uint32_t currentStackIndex
VkExtent2D physicalResolution
VkDisplayModeKHR displayMode
VkDisplayPlaneAlphaFlagBitsKHR alphaMode
VkSurfaceTransformFlagBitsKHR transform
#define VULKAN_INSTANCE_FUNCTION(name)
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *pName)
VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties)
VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physicalDevice, uint32_t planeIndex, uint32_t *pDisplayCount, VkDisplayKHR *pDisplays)
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPropertiesKHR *pProperties)
VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, uint32_t planeIndex, VkDisplayPlaneCapabilitiesKHR *pCapabilities)
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPlanePropertiesKHR *pProperties)
VkDisplayPlaneAlphaFlagBitsKHR
@ VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_PREMULTIPLIED_BIT_KHR
@ VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR
@ VK_DISPLAY_PLANE_ALPHA_GLOBAL_BIT_KHR
@ VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_BIT_KHR
VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, VkPhysicalDevice *pPhysicalDevices)
#define VK_KHR_DISPLAY_EXTENSION_NAME
VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties)
@ VK_ERROR_VALIDATION_FAILED_EXT
@ VK_ERROR_INVALID_SHADER_NV
@ VK_ERROR_EXTENSION_NOT_PRESENT
@ VK_ERROR_OUT_OF_POOL_MEMORY_KHR
@ VK_ERROR_OUT_OF_HOST_MEMORY
@ VK_ERROR_INITIALIZATION_FAILED
@ VK_ERROR_INCOMPATIBLE_DISPLAY_KHR
@ VK_ERROR_OUT_OF_DEVICE_MEMORY
@ VK_ERROR_NATIVE_WINDOW_IN_USE_KHR
@ VK_ERROR_OUT_OF_DATE_KHR
@ VK_ERROR_FORMAT_NOT_SUPPORTED
@ VK_ERROR_FRAGMENTED_POOL
@ VK_ERROR_SURFACE_LOST_KHR
@ VK_ERROR_FEATURE_NOT_PRESENT
@ VK_ERROR_TOO_MANY_OBJECTS
@ VK_ERROR_MEMORY_MAP_FAILED
@ VK_ERROR_LAYER_NOT_PRESENT
@ VK_ERROR_INCOMPATIBLE_DRIVER
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR(VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface)
VkResult(VKAPI_PTR * PFN_vkEnumerateInstanceExtensionProperties)(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties)
@ VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)
@ VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR