testvulkan: support multiple windows.

Fixes #4363.
This commit is contained in:
Ryan C. Gordon 2021-08-23 20:18:57 -04:00
parent 13ec545936
commit abba181118
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 210 additions and 181 deletions

View File

@ -174,6 +174,7 @@ static const char *getVulkanResultString(VkResult result)
typedef struct VulkanContext typedef struct VulkanContext
{ {
SDL_Window *window;
VkInstance instance; VkInstance instance;
VkDevice device; VkDevice device;
VkSurfaceKHR surface; VkSurfaceKHR surface;
@ -202,7 +203,8 @@ typedef struct VulkanContext
} VulkanContext; } VulkanContext;
static SDLTest_CommonState *state; static SDLTest_CommonState *state;
static VulkanContext vulkanContext = {0}; static VulkanContext *vulkanContexts = NULL; // an array of state->num_windows items
static VulkanContext *vulkanContext = NULL; // for the currently-rendering window
static void shutdownVulkan(void); static void shutdownVulkan(void);
@ -277,11 +279,11 @@ static void createInstance(void)
} }
instanceCreateInfo.enabledExtensionCount = extensionCount; instanceCreateInfo.enabledExtensionCount = extensionCount;
instanceCreateInfo.ppEnabledExtensionNames = extensions; instanceCreateInfo.ppEnabledExtensionNames = extensions;
result = vkCreateInstance(&instanceCreateInfo, NULL, &vulkanContext.instance); result = vkCreateInstance(&instanceCreateInfo, NULL, &vulkanContext->instance);
SDL_free((void*)extensions); SDL_free((void*)extensions);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
vulkanContext.instance = VK_NULL_HANDLE; vulkanContext->instance = VK_NULL_HANDLE;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkCreateInstance(): %s\n", "vkCreateInstance(): %s\n",
getVulkanResultString(result)); getVulkanResultString(result));
@ -294,7 +296,7 @@ static void loadInstanceFunctions(void)
#define VULKAN_DEVICE_FUNCTION(name) #define VULKAN_DEVICE_FUNCTION(name)
#define VULKAN_GLOBAL_FUNCTION(name) #define VULKAN_GLOBAL_FUNCTION(name)
#define VULKAN_INSTANCE_FUNCTION(name) \ #define VULKAN_INSTANCE_FUNCTION(name) \
name = (PFN_##name)vkGetInstanceProcAddr(vulkanContext.instance, #name); \ name = (PFN_##name)vkGetInstanceProcAddr(vulkanContext->instance, #name); \
if(!name) \ if(!name) \
{ \ { \
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \
@ -309,11 +311,11 @@ static void loadInstanceFunctions(void)
static void createSurface(void) static void createSurface(void)
{ {
if(!SDL_Vulkan_CreateSurface(state->windows[0], if(!SDL_Vulkan_CreateSurface(vulkanContext->window,
vulkanContext.instance, vulkanContext->instance,
&vulkanContext.surface)) &vulkanContext->surface))
{ {
vulkanContext.surface = VK_NULL_HANDLE; vulkanContext->surface = VK_NULL_HANDLE;
SDL_LogError( SDL_LogError(
SDL_LOG_CATEGORY_APPLICATION, "SDL_Vulkan_CreateSurface(): %s\n", SDL_GetError()); SDL_LOG_CATEGORY_APPLICATION, "SDL_Vulkan_CreateSurface(): %s\n", SDL_GetError());
quit(2); quit(2);
@ -331,7 +333,7 @@ static void findPhysicalDevice(void)
uint32_t physicalDeviceIndex; uint32_t physicalDeviceIndex;
VkResult result = VkResult result =
vkEnumeratePhysicalDevices(vulkanContext.instance, &physicalDeviceCount, NULL); vkEnumeratePhysicalDevices(vulkanContext->instance, &physicalDeviceCount, NULL);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
@ -352,7 +354,7 @@ static void findPhysicalDevice(void)
quit(2); quit(2);
} }
result = result =
vkEnumeratePhysicalDevices(vulkanContext.instance, &physicalDeviceCount, physicalDevices); vkEnumeratePhysicalDevices(vulkanContext->instance, &physicalDeviceCount, physicalDevices);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
SDL_free(physicalDevices); SDL_free(physicalDevices);
@ -361,7 +363,7 @@ static void findPhysicalDevice(void)
getVulkanResultString(result)); getVulkanResultString(result));
quit(2); quit(2);
} }
vulkanContext.physicalDevice = NULL; vulkanContext->physicalDevice = NULL;
for(physicalDeviceIndex = 0; physicalDeviceIndex < physicalDeviceCount; for(physicalDeviceIndex = 0; physicalDeviceIndex < physicalDeviceCount;
physicalDeviceIndex++) physicalDeviceIndex++)
{ {
@ -373,10 +375,10 @@ static void findPhysicalDevice(void)
VkPhysicalDevice physicalDevice = physicalDevices[physicalDeviceIndex]; VkPhysicalDevice physicalDevice = physicalDevices[physicalDeviceIndex];
vkGetPhysicalDeviceProperties(physicalDevice, &vulkanContext.physicalDeviceProperties); vkGetPhysicalDeviceProperties(physicalDevice, &vulkanContext->physicalDeviceProperties);
if(VK_VERSION_MAJOR(vulkanContext.physicalDeviceProperties.apiVersion) < 1) if(VK_VERSION_MAJOR(vulkanContext->physicalDeviceProperties.apiVersion) < 1)
continue; continue;
vkGetPhysicalDeviceFeatures(physicalDevice, &vulkanContext.physicalDeviceFeatures); vkGetPhysicalDeviceFeatures(physicalDevice, &vulkanContext->physicalDeviceFeatures);
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamiliesCount, NULL); vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamiliesCount, NULL);
if(queueFamiliesCount == 0) if(queueFamiliesCount == 0)
continue; continue;
@ -396,8 +398,8 @@ static void findPhysicalDevice(void)
} }
vkGetPhysicalDeviceQueueFamilyProperties( vkGetPhysicalDeviceQueueFamilyProperties(
physicalDevice, &queueFamiliesCount, queueFamiliesProperties); physicalDevice, &queueFamiliesCount, queueFamiliesProperties);
vulkanContext.graphicsQueueFamilyIndex = queueFamiliesCount; vulkanContext->graphicsQueueFamilyIndex = queueFamiliesCount;
vulkanContext.presentQueueFamilyIndex = queueFamiliesCount; vulkanContext->presentQueueFamilyIndex = queueFamiliesCount;
for(queueFamilyIndex = 0; queueFamilyIndex < queueFamiliesCount; for(queueFamilyIndex = 0; queueFamilyIndex < queueFamiliesCount;
queueFamilyIndex++) queueFamilyIndex++)
{ {
@ -406,9 +408,9 @@ static void findPhysicalDevice(void)
if(queueFamiliesProperties[queueFamilyIndex].queueCount == 0) if(queueFamiliesProperties[queueFamilyIndex].queueCount == 0)
continue; continue;
if(queueFamiliesProperties[queueFamilyIndex].queueFlags & VK_QUEUE_GRAPHICS_BIT) if(queueFamiliesProperties[queueFamilyIndex].queueFlags & VK_QUEUE_GRAPHICS_BIT)
vulkanContext.graphicsQueueFamilyIndex = queueFamilyIndex; vulkanContext->graphicsQueueFamilyIndex = queueFamilyIndex;
result = vkGetPhysicalDeviceSurfaceSupportKHR( result = vkGetPhysicalDeviceSurfaceSupportKHR(
physicalDevice, queueFamilyIndex, vulkanContext.surface, &supported); physicalDevice, queueFamilyIndex, vulkanContext->surface, &supported);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
SDL_free(physicalDevices); SDL_free(physicalDevices);
@ -421,14 +423,14 @@ static void findPhysicalDevice(void)
} }
if(supported) if(supported)
{ {
vulkanContext.presentQueueFamilyIndex = queueFamilyIndex; vulkanContext->presentQueueFamilyIndex = queueFamilyIndex;
if(queueFamiliesProperties[queueFamilyIndex].queueFlags & VK_QUEUE_GRAPHICS_BIT) if(queueFamiliesProperties[queueFamilyIndex].queueFlags & VK_QUEUE_GRAPHICS_BIT)
break; // use this queue because it can present and do graphics break; // use this queue because it can present and do graphics
} }
} }
if(vulkanContext.graphicsQueueFamilyIndex == queueFamiliesCount) // no good queues found if(vulkanContext->graphicsQueueFamilyIndex == queueFamiliesCount) // no good queues found
continue; continue;
if(vulkanContext.presentQueueFamilyIndex == queueFamiliesCount) // no good queues found if(vulkanContext->presentQueueFamilyIndex == queueFamiliesCount) // no good queues found
continue; continue;
result = result =
vkEnumerateDeviceExtensionProperties(physicalDevice, NULL, &deviceExtensionCount, NULL); vkEnumerateDeviceExtensionProperties(physicalDevice, NULL, &deviceExtensionCount, NULL);
@ -480,13 +482,13 @@ static void findPhysicalDevice(void)
} }
if(!hasSwapchainExtension) if(!hasSwapchainExtension)
continue; continue;
vulkanContext.physicalDevice = physicalDevice; vulkanContext->physicalDevice = physicalDevice;
break; break;
} }
SDL_free(physicalDevices); SDL_free(physicalDevices);
SDL_free(queueFamiliesProperties); SDL_free(queueFamiliesProperties);
SDL_free(deviceExtensions); SDL_free(deviceExtensions);
if(!vulkanContext.physicalDevice) if(!vulkanContext->physicalDevice)
{ {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Vulkan: no viable physical devices found"); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Vulkan: no viable physical devices found");
quit(2); quit(2);
@ -504,7 +506,7 @@ static void createDevice(void)
VkResult result; VkResult result;
deviceQueueCreateInfo->sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; deviceQueueCreateInfo->sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
deviceQueueCreateInfo->queueFamilyIndex = vulkanContext.graphicsQueueFamilyIndex; deviceQueueCreateInfo->queueFamilyIndex = vulkanContext->graphicsQueueFamilyIndex;
deviceQueueCreateInfo->queueCount = 1; deviceQueueCreateInfo->queueCount = 1;
deviceQueueCreateInfo->pQueuePriorities = &queuePriority[0]; deviceQueueCreateInfo->pQueuePriorities = &queuePriority[0];
@ -515,10 +517,10 @@ static void createDevice(void)
deviceCreateInfo.enabledExtensionCount = SDL_arraysize(deviceExtensionNames); deviceCreateInfo.enabledExtensionCount = SDL_arraysize(deviceExtensionNames);
deviceCreateInfo.ppEnabledExtensionNames = deviceExtensionNames; deviceCreateInfo.ppEnabledExtensionNames = deviceExtensionNames;
result = vkCreateDevice( result = vkCreateDevice(
vulkanContext.physicalDevice, &deviceCreateInfo, NULL, &vulkanContext.device); vulkanContext->physicalDevice, &deviceCreateInfo, NULL, &vulkanContext->device);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
vulkanContext.device = VK_NULL_HANDLE; vulkanContext->device = VK_NULL_HANDLE;
SDL_LogError( SDL_LogError(
SDL_LOG_CATEGORY_APPLICATION, "vkCreateDevice(): %s\n", getVulkanResultString(result)); SDL_LOG_CATEGORY_APPLICATION, "vkCreateDevice(): %s\n", getVulkanResultString(result));
quit(2); quit(2);
@ -528,7 +530,7 @@ static void createDevice(void)
static void loadDeviceFunctions(void) static void loadDeviceFunctions(void)
{ {
#define VULKAN_DEVICE_FUNCTION(name) \ #define VULKAN_DEVICE_FUNCTION(name) \
name = (PFN_##name)vkGetDeviceProcAddr(vulkanContext.device, #name); \ name = (PFN_##name)vkGetDeviceProcAddr(vulkanContext->device, #name); \
if(!name) \ if(!name) \
{ \ { \
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \
@ -547,17 +549,17 @@ static void loadDeviceFunctions(void)
static void getQueues(void) static void getQueues(void)
{ {
vkGetDeviceQueue(vulkanContext.device, vkGetDeviceQueue(vulkanContext->device,
vulkanContext.graphicsQueueFamilyIndex, vulkanContext->graphicsQueueFamilyIndex,
0, 0,
&vulkanContext.graphicsQueue); &vulkanContext->graphicsQueue);
if(vulkanContext.graphicsQueueFamilyIndex != vulkanContext.presentQueueFamilyIndex) if(vulkanContext->graphicsQueueFamilyIndex != vulkanContext->presentQueueFamilyIndex)
vkGetDeviceQueue(vulkanContext.device, vkGetDeviceQueue(vulkanContext->device,
vulkanContext.presentQueueFamilyIndex, vulkanContext->presentQueueFamilyIndex,
0, 0,
&vulkanContext.presentQueue); &vulkanContext->presentQueue);
else else
vulkanContext.presentQueue = vulkanContext.graphicsQueue; vulkanContext->presentQueue = vulkanContext->graphicsQueue;
} }
static void createSemaphore(VkSemaphore *semaphore) static void createSemaphore(VkSemaphore *semaphore)
@ -566,7 +568,7 @@ static void createSemaphore(VkSemaphore *semaphore)
VkSemaphoreCreateInfo createInfo = {0}; VkSemaphoreCreateInfo createInfo = {0};
createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
result = vkCreateSemaphore(vulkanContext.device, &createInfo, NULL, semaphore); result = vkCreateSemaphore(vulkanContext->device, &createInfo, NULL, semaphore);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
*semaphore = VK_NULL_HANDLE; *semaphore = VK_NULL_HANDLE;
@ -579,14 +581,14 @@ static void createSemaphore(VkSemaphore *semaphore)
static void createSemaphores(void) static void createSemaphores(void)
{ {
createSemaphore(&vulkanContext.imageAvailableSemaphore); createSemaphore(&vulkanContext->imageAvailableSemaphore);
createSemaphore(&vulkanContext.renderingFinishedSemaphore); createSemaphore(&vulkanContext->renderingFinishedSemaphore);
} }
static void getSurfaceCaps(void) static void getSurfaceCaps(void)
{ {
VkResult result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR( VkResult result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
vulkanContext.physicalDevice, vulkanContext.surface, &vulkanContext.surfaceCapabilities); vulkanContext->physicalDevice, vulkanContext->surface, &vulkanContext->surfaceCapabilities);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
@ -596,7 +598,7 @@ static void getSurfaceCaps(void)
} }
// check surface usage // check surface usage
if(!(vulkanContext.surfaceCapabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) if(!(vulkanContext->surfaceCapabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT))
{ {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Vulkan surface doesn't support VK_IMAGE_USAGE_TRANSFER_DST_BIT\n"); "Vulkan surface doesn't support VK_IMAGE_USAGE_TRANSFER_DST_BIT\n");
@ -606,38 +608,38 @@ static void getSurfaceCaps(void)
static void getSurfaceFormats(void) static void getSurfaceFormats(void)
{ {
VkResult result = vkGetPhysicalDeviceSurfaceFormatsKHR(vulkanContext.physicalDevice, VkResult result = vkGetPhysicalDeviceSurfaceFormatsKHR(vulkanContext->physicalDevice,
vulkanContext.surface, vulkanContext->surface,
&vulkanContext.surfaceFormatsCount, &vulkanContext->surfaceFormatsCount,
NULL); NULL);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
vulkanContext.surfaceFormatsCount = 0; vulkanContext->surfaceFormatsCount = 0;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkGetPhysicalDeviceSurfaceFormatsKHR(): %s\n", "vkGetPhysicalDeviceSurfaceFormatsKHR(): %s\n",
getVulkanResultString(result)); getVulkanResultString(result));
quit(2); quit(2);
} }
if(vulkanContext.surfaceFormatsCount > vulkanContext.surfaceFormatsAllocatedCount) if(vulkanContext->surfaceFormatsCount > vulkanContext->surfaceFormatsAllocatedCount)
{ {
vulkanContext.surfaceFormatsAllocatedCount = vulkanContext.surfaceFormatsCount; vulkanContext->surfaceFormatsAllocatedCount = vulkanContext->surfaceFormatsCount;
SDL_free(vulkanContext.surfaceFormats); SDL_free(vulkanContext->surfaceFormats);
vulkanContext.surfaceFormats = vulkanContext->surfaceFormats =
SDL_malloc(sizeof(VkSurfaceFormatKHR) * vulkanContext.surfaceFormatsAllocatedCount); SDL_malloc(sizeof(VkSurfaceFormatKHR) * vulkanContext->surfaceFormatsAllocatedCount);
if(!vulkanContext.surfaceFormats) if(!vulkanContext->surfaceFormats)
{ {
vulkanContext.surfaceFormatsCount = 0; vulkanContext->surfaceFormatsCount = 0;
SDL_OutOfMemory(); SDL_OutOfMemory();
quit(2); quit(2);
} }
} }
result = vkGetPhysicalDeviceSurfaceFormatsKHR(vulkanContext.physicalDevice, result = vkGetPhysicalDeviceSurfaceFormatsKHR(vulkanContext->physicalDevice,
vulkanContext.surface, vulkanContext->surface,
&vulkanContext.surfaceFormatsCount, &vulkanContext->surfaceFormatsCount,
vulkanContext.surfaceFormats); vulkanContext->surfaceFormats);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
vulkanContext.surfaceFormatsCount = 0; vulkanContext->surfaceFormatsCount = 0;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkGetPhysicalDeviceSurfaceFormatsKHR(): %s\n", "vkGetPhysicalDeviceSurfaceFormatsKHR(): %s\n",
getVulkanResultString(result)); getVulkanResultString(result));
@ -649,33 +651,33 @@ static void getSwapchainImages(void)
{ {
VkResult result; VkResult result;
SDL_free(vulkanContext.swapchainImages); SDL_free(vulkanContext->swapchainImages);
vulkanContext.swapchainImages = NULL; vulkanContext->swapchainImages = NULL;
result = vkGetSwapchainImagesKHR( result = vkGetSwapchainImagesKHR(
vulkanContext.device, vulkanContext.swapchain, &vulkanContext.swapchainImageCount, NULL); vulkanContext->device, vulkanContext->swapchain, &vulkanContext->swapchainImageCount, NULL);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
vulkanContext.swapchainImageCount = 0; vulkanContext->swapchainImageCount = 0;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkGetSwapchainImagesKHR(): %s\n", "vkGetSwapchainImagesKHR(): %s\n",
getVulkanResultString(result)); getVulkanResultString(result));
quit(2); quit(2);
} }
vulkanContext.swapchainImages = SDL_malloc(sizeof(VkImage) * vulkanContext.swapchainImageCount); vulkanContext->swapchainImages = SDL_malloc(sizeof(VkImage) * vulkanContext->swapchainImageCount);
if(!vulkanContext.swapchainImages) if(!vulkanContext->swapchainImages)
{ {
SDL_OutOfMemory(); SDL_OutOfMemory();
quit(2); quit(2);
} }
result = vkGetSwapchainImagesKHR(vulkanContext.device, result = vkGetSwapchainImagesKHR(vulkanContext->device,
vulkanContext.swapchain, vulkanContext->swapchain,
&vulkanContext.swapchainImageCount, &vulkanContext->swapchainImageCount,
vulkanContext.swapchainImages); vulkanContext->swapchainImages);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
SDL_free(vulkanContext.swapchainImages); SDL_free(vulkanContext->swapchainImages);
vulkanContext.swapchainImages = NULL; vulkanContext->swapchainImages = NULL;
vulkanContext.swapchainImageCount = 0; vulkanContext->swapchainImageCount = 0;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkGetSwapchainImagesKHR(): %s\n", "vkGetSwapchainImagesKHR(): %s\n",
getVulkanResultString(result)); getVulkanResultString(result));
@ -691,69 +693,69 @@ static SDL_bool createSwapchain(void)
VkResult result; VkResult result;
// pick an image count // pick an image count
vulkanContext.swapchainDesiredImageCount = vulkanContext.surfaceCapabilities.minImageCount + 1; vulkanContext->swapchainDesiredImageCount = vulkanContext->surfaceCapabilities.minImageCount + 1;
if(vulkanContext.swapchainDesiredImageCount > vulkanContext.surfaceCapabilities.maxImageCount if(vulkanContext->swapchainDesiredImageCount > vulkanContext->surfaceCapabilities.maxImageCount
&& vulkanContext.surfaceCapabilities.maxImageCount > 0) && vulkanContext->surfaceCapabilities.maxImageCount > 0)
vulkanContext.swapchainDesiredImageCount = vulkanContext.surfaceCapabilities.maxImageCount; vulkanContext->swapchainDesiredImageCount = vulkanContext->surfaceCapabilities.maxImageCount;
// pick a format // pick a format
if(vulkanContext.surfaceFormatsCount == 1 if(vulkanContext->surfaceFormatsCount == 1
&& vulkanContext.surfaceFormats[0].format == VK_FORMAT_UNDEFINED) && vulkanContext->surfaceFormats[0].format == VK_FORMAT_UNDEFINED)
{ {
// aren't any preferred formats, so we pick // aren't any preferred formats, so we pick
vulkanContext.surfaceFormat.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; vulkanContext->surfaceFormat.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
vulkanContext.surfaceFormat.format = VK_FORMAT_R8G8B8A8_UNORM; vulkanContext->surfaceFormat.format = VK_FORMAT_R8G8B8A8_UNORM;
} }
else else
{ {
vulkanContext.surfaceFormat = vulkanContext.surfaceFormats[0]; vulkanContext->surfaceFormat = vulkanContext->surfaceFormats[0];
for(i = 0; i < vulkanContext.surfaceFormatsCount; i++) for(i = 0; i < vulkanContext->surfaceFormatsCount; i++)
{ {
if(vulkanContext.surfaceFormats[i].format == VK_FORMAT_R8G8B8A8_UNORM) if(vulkanContext->surfaceFormats[i].format == VK_FORMAT_R8G8B8A8_UNORM)
{ {
vulkanContext.surfaceFormat = vulkanContext.surfaceFormats[i]; vulkanContext->surfaceFormat = vulkanContext->surfaceFormats[i];
break; break;
} }
} }
} }
// get size // get size
SDL_Vulkan_GetDrawableSize(state->windows[0], &w, &h); SDL_Vulkan_GetDrawableSize(vulkanContext->window, &w, &h);
// Clamp the size to the allowable image extent. // Clamp the size to the allowable image extent.
// SDL_Vulkan_GetDrawableSize()'s result it not always in this range (bug #3287) // SDL_Vulkan_GetDrawableSize()'s result it not always in this range (bug #3287)
vulkanContext.swapchainSize.width = SDL_clamp(w, vulkanContext->swapchainSize.width = SDL_clamp(w,
vulkanContext.surfaceCapabilities.minImageExtent.width, vulkanContext->surfaceCapabilities.minImageExtent.width,
vulkanContext.surfaceCapabilities.maxImageExtent.width); vulkanContext->surfaceCapabilities.maxImageExtent.width);
vulkanContext.swapchainSize.height = SDL_clamp(h, vulkanContext->swapchainSize.height = SDL_clamp(h,
vulkanContext.surfaceCapabilities.minImageExtent.height, vulkanContext->surfaceCapabilities.minImageExtent.height,
vulkanContext.surfaceCapabilities.maxImageExtent.height); vulkanContext->surfaceCapabilities.maxImageExtent.height);
if(w == 0 || h == 0) if(w == 0 || h == 0)
return SDL_FALSE; return SDL_FALSE;
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
createInfo.surface = vulkanContext.surface; createInfo.surface = vulkanContext->surface;
createInfo.minImageCount = vulkanContext.swapchainDesiredImageCount; createInfo.minImageCount = vulkanContext->swapchainDesiredImageCount;
createInfo.imageFormat = vulkanContext.surfaceFormat.format; createInfo.imageFormat = vulkanContext->surfaceFormat.format;
createInfo.imageColorSpace = vulkanContext.surfaceFormat.colorSpace; createInfo.imageColorSpace = vulkanContext->surfaceFormat.colorSpace;
createInfo.imageExtent = vulkanContext.swapchainSize; createInfo.imageExtent = vulkanContext->swapchainSize;
createInfo.imageArrayLayers = 1; createInfo.imageArrayLayers = 1;
createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
createInfo.preTransform = vulkanContext.surfaceCapabilities.currentTransform; createInfo.preTransform = vulkanContext->surfaceCapabilities.currentTransform;
createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
createInfo.presentMode = VK_PRESENT_MODE_FIFO_KHR; createInfo.presentMode = VK_PRESENT_MODE_FIFO_KHR;
createInfo.clipped = VK_TRUE; createInfo.clipped = VK_TRUE;
createInfo.oldSwapchain = vulkanContext.swapchain; createInfo.oldSwapchain = vulkanContext->swapchain;
result = result =
vkCreateSwapchainKHR(vulkanContext.device, &createInfo, NULL, &vulkanContext.swapchain); vkCreateSwapchainKHR(vulkanContext->device, &createInfo, NULL, &vulkanContext->swapchain);
if(createInfo.oldSwapchain) if(createInfo.oldSwapchain)
vkDestroySwapchainKHR(vulkanContext.device, createInfo.oldSwapchain, NULL); vkDestroySwapchainKHR(vulkanContext->device, createInfo.oldSwapchain, NULL);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
vulkanContext.swapchain = VK_NULL_HANDLE; vulkanContext->swapchain = VK_NULL_HANDLE;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkCreateSwapchainKHR(): %s\n", "vkCreateSwapchainKHR(): %s\n",
getVulkanResultString(result)); getVulkanResultString(result));
@ -765,29 +767,29 @@ static SDL_bool createSwapchain(void)
static void destroySwapchain(void) static void destroySwapchain(void)
{ {
if(vulkanContext.swapchain) if(vulkanContext->swapchain)
vkDestroySwapchainKHR(vulkanContext.device, vulkanContext.swapchain, NULL); vkDestroySwapchainKHR(vulkanContext->device, vulkanContext->swapchain, NULL);
vulkanContext.swapchain = VK_NULL_HANDLE; vulkanContext->swapchain = VK_NULL_HANDLE;
SDL_free(vulkanContext.swapchainImages); SDL_free(vulkanContext->swapchainImages);
vulkanContext.swapchainImages = NULL; vulkanContext->swapchainImages = NULL;
} }
static void destroyCommandBuffers(void) static void destroyCommandBuffers(void)
{ {
if(vulkanContext.commandBuffers) if(vulkanContext->commandBuffers)
vkFreeCommandBuffers(vulkanContext.device, vkFreeCommandBuffers(vulkanContext->device,
vulkanContext.commandPool, vulkanContext->commandPool,
vulkanContext.swapchainImageCount, vulkanContext->swapchainImageCount,
vulkanContext.commandBuffers); vulkanContext->commandBuffers);
SDL_free(vulkanContext.commandBuffers); SDL_free(vulkanContext->commandBuffers);
vulkanContext.commandBuffers = NULL; vulkanContext->commandBuffers = NULL;
} }
static void destroyCommandPool(void) static void destroyCommandPool(void)
{ {
if(vulkanContext.commandPool) if(vulkanContext->commandPool)
vkDestroyCommandPool(vulkanContext.device, vulkanContext.commandPool, NULL); vkDestroyCommandPool(vulkanContext->device, vulkanContext->commandPool, NULL);
vulkanContext.commandPool = VK_NULL_HANDLE; vulkanContext->commandPool = VK_NULL_HANDLE;
} }
static void createCommandPool(void) static void createCommandPool(void)
@ -798,12 +800,12 @@ static void createCommandPool(void)
createInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; createInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
createInfo.flags = createInfo.flags =
VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT | VK_COMMAND_POOL_CREATE_TRANSIENT_BIT; VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT | VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
createInfo.queueFamilyIndex = vulkanContext.graphicsQueueFamilyIndex; createInfo.queueFamilyIndex = vulkanContext->graphicsQueueFamilyIndex;
result = result =
vkCreateCommandPool(vulkanContext.device, &createInfo, NULL, &vulkanContext.commandPool); vkCreateCommandPool(vulkanContext->device, &createInfo, NULL, &vulkanContext->commandPool);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
vulkanContext.commandPool = VK_NULL_HANDLE; vulkanContext->commandPool = VK_NULL_HANDLE;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkCreateCommandPool(): %s\n", "vkCreateCommandPool(): %s\n",
getVulkanResultString(result)); getVulkanResultString(result));
@ -817,17 +819,17 @@ static void createCommandBuffers(void)
VkCommandBufferAllocateInfo allocateInfo = {0}; VkCommandBufferAllocateInfo allocateInfo = {0};
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocateInfo.commandPool = vulkanContext.commandPool; allocateInfo.commandPool = vulkanContext->commandPool;
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocateInfo.commandBufferCount = vulkanContext.swapchainImageCount; allocateInfo.commandBufferCount = vulkanContext->swapchainImageCount;
vulkanContext.commandBuffers = vulkanContext->commandBuffers =
SDL_malloc(sizeof(VkCommandBuffer) * vulkanContext.swapchainImageCount); SDL_malloc(sizeof(VkCommandBuffer) * vulkanContext->swapchainImageCount);
result = result =
vkAllocateCommandBuffers(vulkanContext.device, &allocateInfo, vulkanContext.commandBuffers); vkAllocateCommandBuffers(vulkanContext->device, &allocateInfo, vulkanContext->commandBuffers);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
SDL_free(vulkanContext.commandBuffers); SDL_free(vulkanContext->commandBuffers);
vulkanContext.commandBuffers = NULL; vulkanContext->commandBuffers = NULL;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkAllocateCommandBuffers(): %s\n", "vkAllocateCommandBuffers(): %s\n",
getVulkanResultString(result)); getVulkanResultString(result));
@ -839,13 +841,13 @@ static void createFences(void)
{ {
uint32_t i; uint32_t i;
vulkanContext.fences = SDL_malloc(sizeof(VkFence) * vulkanContext.swapchainImageCount); vulkanContext->fences = SDL_malloc(sizeof(VkFence) * vulkanContext->swapchainImageCount);
if(!vulkanContext.fences) if(!vulkanContext->fences)
{ {
SDL_OutOfMemory(); SDL_OutOfMemory();
quit(2); quit(2);
} }
for(i = 0; i < vulkanContext.swapchainImageCount; i++) for(i = 0; i < vulkanContext->swapchainImageCount; i++)
{ {
VkResult result; VkResult result;
@ -853,15 +855,15 @@ static void createFences(void)
createInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; createInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
createInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; createInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
result = result =
vkCreateFence(vulkanContext.device, &createInfo, NULL, &vulkanContext.fences[i]); vkCreateFence(vulkanContext->device, &createInfo, NULL, &vulkanContext->fences[i]);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
for(; i > 0; i--) for(; i > 0; i--)
{ {
vkDestroyFence(vulkanContext.device, vulkanContext.fences[i - 1], NULL); vkDestroyFence(vulkanContext->device, vulkanContext->fences[i - 1], NULL);
} }
SDL_free(vulkanContext.fences); SDL_free(vulkanContext->fences);
vulkanContext.fences = NULL; vulkanContext->fences = NULL;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkCreateFence(): %s\n", "vkCreateFence(): %s\n",
getVulkanResultString(result)); getVulkanResultString(result));
@ -874,14 +876,14 @@ static void destroyFences(void)
{ {
uint32_t i; uint32_t i;
if(!vulkanContext.fences) if(!vulkanContext->fences)
return; return;
for(i = 0; i < vulkanContext.swapchainImageCount; i++) for(i = 0; i < vulkanContext->swapchainImageCount; i++)
{ {
vkDestroyFence(vulkanContext.device, vulkanContext.fences[i], NULL); vkDestroyFence(vulkanContext->device, vulkanContext->fences[i], NULL);
} }
SDL_free(vulkanContext.fences); SDL_free(vulkanContext->fences);
vulkanContext.fences = NULL; vulkanContext->fences = NULL;
} }
static void recordPipelineImageBarrier(VkCommandBuffer commandBuffer, static void recordPipelineImageBarrier(VkCommandBuffer commandBuffer,
@ -919,8 +921,8 @@ static void recordPipelineImageBarrier(VkCommandBuffer commandBuffer,
static void rerecordCommandBuffer(uint32_t frameIndex, const VkClearColorValue *clearColor) static void rerecordCommandBuffer(uint32_t frameIndex, const VkClearColorValue *clearColor)
{ {
VkCommandBuffer commandBuffer = vulkanContext.commandBuffers[frameIndex]; VkCommandBuffer commandBuffer = vulkanContext->commandBuffers[frameIndex];
VkImage image = vulkanContext.swapchainImages[frameIndex]; VkImage image = vulkanContext->swapchainImages[frameIndex];
VkCommandBufferBeginInfo beginInfo = {0}; VkCommandBufferBeginInfo beginInfo = {0};
VkImageSubresourceRange clearRange = {0}; VkImageSubresourceRange clearRange = {0};
@ -995,8 +997,19 @@ static SDL_bool createNewSwapchainAndSwapchainSpecificStuff(void)
static void initVulkan(void) static void initVulkan(void)
{ {
int i;
SDL_Vulkan_LoadLibrary(NULL); SDL_Vulkan_LoadLibrary(NULL);
SDL_memset(&vulkanContext, 0, sizeof(VulkanContext));
vulkanContexts = (VulkanContext *) SDL_calloc(state->num_windows, sizeof (VulkanContext));
if (!vulkanContexts) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
quit(2);
}
for (i = 0; i < state->num_windows; ++i) {
vulkanContext = &vulkanContexts[i];
vulkanContext->window = state->windows[i];
loadGlobalFunctions(); loadGlobalFunctions();
createInstance(); createInstance();
loadInstanceFunctions(); loadInstanceFunctions();
@ -1007,24 +1020,34 @@ static void initVulkan(void)
getQueues(); getQueues();
createSemaphores(); createSemaphores();
createNewSwapchainAndSwapchainSpecificStuff(); createNewSwapchainAndSwapchainSpecificStuff();
}
} }
static void shutdownVulkan(void) static void shutdownVulkan(void)
{ {
if(vulkanContext.device && vkDeviceWaitIdle) if (vulkanContexts) {
vkDeviceWaitIdle(vulkanContext.device); int i;
for (i = 0; i < state->num_windows; ++i) {
vulkanContext = &vulkanContexts[i];
if(vulkanContext->device && vkDeviceWaitIdle)
vkDeviceWaitIdle(vulkanContext->device);
destroySwapchainAndSwapchainSpecificStuff(SDL_TRUE); destroySwapchainAndSwapchainSpecificStuff(SDL_TRUE);
if(vulkanContext.imageAvailableSemaphore && vkDestroySemaphore) if(vulkanContext->imageAvailableSemaphore && vkDestroySemaphore)
vkDestroySemaphore(vulkanContext.device, vulkanContext.imageAvailableSemaphore, NULL); vkDestroySemaphore(vulkanContext->device, vulkanContext->imageAvailableSemaphore, NULL);
if(vulkanContext.renderingFinishedSemaphore && vkDestroySemaphore) if(vulkanContext->renderingFinishedSemaphore && vkDestroySemaphore)
vkDestroySemaphore(vulkanContext.device, vulkanContext.renderingFinishedSemaphore, NULL); vkDestroySemaphore(vulkanContext->device, vulkanContext->renderingFinishedSemaphore, NULL);
if(vulkanContext.device && vkDestroyDevice) if(vulkanContext->device && vkDestroyDevice)
vkDestroyDevice(vulkanContext.device, NULL); vkDestroyDevice(vulkanContext->device, NULL);
if(vulkanContext.surface && vkDestroySurfaceKHR) if(vulkanContext->surface && vkDestroySurfaceKHR)
vkDestroySurfaceKHR(vulkanContext.instance, vulkanContext.surface, NULL); vkDestroySurfaceKHR(vulkanContext->instance, vulkanContext->surface, NULL);
if(vulkanContext.instance && vkDestroyInstance) if(vulkanContext->instance && vkDestroyInstance)
vkDestroyInstance(vulkanContext.instance, NULL); vkDestroyInstance(vulkanContext->instance, NULL);
SDL_free(vulkanContext.surfaceFormats); SDL_free(vulkanContext->surfaceFormats);
}
SDL_free(vulkanContexts);
vulkanContexts = NULL;
}
SDL_Vulkan_UnloadLibrary(); SDL_Vulkan_UnloadLibrary();
} }
@ -1039,17 +1062,17 @@ static SDL_bool render(void)
VkPresentInfoKHR presentInfo = {0}; VkPresentInfoKHR presentInfo = {0};
int w, h; int w, h;
if(!vulkanContext.swapchain) if(!vulkanContext->swapchain)
{ {
SDL_bool retval = createNewSwapchainAndSwapchainSpecificStuff(); SDL_bool retval = createNewSwapchainAndSwapchainSpecificStuff();
if(!retval) if(!retval)
SDL_Delay(100); SDL_Delay(100);
return retval; return retval;
} }
result = vkAcquireNextImageKHR(vulkanContext.device, result = vkAcquireNextImageKHR(vulkanContext->device,
vulkanContext.swapchain, vulkanContext->swapchain,
UINT64_MAX, UINT64_MAX,
vulkanContext.imageAvailableSemaphore, vulkanContext->imageAvailableSemaphore,
VK_NULL_HANDLE, VK_NULL_HANDLE,
&frameIndex); &frameIndex);
if(result == VK_ERROR_OUT_OF_DATE_KHR) if(result == VK_ERROR_OUT_OF_DATE_KHR)
@ -1062,14 +1085,14 @@ static SDL_bool render(void)
quit(2); quit(2);
} }
result = vkWaitForFences( result = vkWaitForFences(
vulkanContext.device, 1, &vulkanContext.fences[frameIndex], VK_FALSE, UINT64_MAX); vulkanContext->device, 1, &vulkanContext->fences[frameIndex], VK_FALSE, UINT64_MAX);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
SDL_LogError( SDL_LogError(
SDL_LOG_CATEGORY_APPLICATION, "vkWaitForFences(): %s\n", getVulkanResultString(result)); SDL_LOG_CATEGORY_APPLICATION, "vkWaitForFences(): %s\n", getVulkanResultString(result));
quit(2); quit(2);
} }
result = vkResetFences(vulkanContext.device, 1, &vulkanContext.fences[frameIndex]); result = vkResetFences(vulkanContext->device, 1, &vulkanContext->fences[frameIndex]);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
SDL_LogError( SDL_LogError(
@ -1084,14 +1107,14 @@ static SDL_bool render(void)
rerecordCommandBuffer(frameIndex, &clearColor); rerecordCommandBuffer(frameIndex, &clearColor);
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submitInfo.waitSemaphoreCount = 1; submitInfo.waitSemaphoreCount = 1;
submitInfo.pWaitSemaphores = &vulkanContext.imageAvailableSemaphore; submitInfo.pWaitSemaphores = &vulkanContext->imageAvailableSemaphore;
submitInfo.pWaitDstStageMask = &waitDestStageMask; submitInfo.pWaitDstStageMask = &waitDestStageMask;
submitInfo.commandBufferCount = 1; submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &vulkanContext.commandBuffers[frameIndex]; submitInfo.pCommandBuffers = &vulkanContext->commandBuffers[frameIndex];
submitInfo.signalSemaphoreCount = 1; submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = &vulkanContext.renderingFinishedSemaphore; submitInfo.pSignalSemaphores = &vulkanContext->renderingFinishedSemaphore;
result = vkQueueSubmit( result = vkQueueSubmit(
vulkanContext.graphicsQueue, 1, &submitInfo, vulkanContext.fences[frameIndex]); vulkanContext->graphicsQueue, 1, &submitInfo, vulkanContext->fences[frameIndex]);
if(result != VK_SUCCESS) if(result != VK_SUCCESS)
{ {
SDL_LogError( SDL_LogError(
@ -1100,11 +1123,11 @@ static SDL_bool render(void)
} }
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
presentInfo.waitSemaphoreCount = 1; presentInfo.waitSemaphoreCount = 1;
presentInfo.pWaitSemaphores = &vulkanContext.renderingFinishedSemaphore; presentInfo.pWaitSemaphores = &vulkanContext->renderingFinishedSemaphore;
presentInfo.swapchainCount = 1; presentInfo.swapchainCount = 1;
presentInfo.pSwapchains = &vulkanContext.swapchain; presentInfo.pSwapchains = &vulkanContext->swapchain;
presentInfo.pImageIndices = &frameIndex; presentInfo.pImageIndices = &frameIndex;
result = vkQueuePresentKHR(vulkanContext.presentQueue, &presentInfo); result = vkQueuePresentKHR(vulkanContext->presentQueue, &presentInfo);
if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
{ {
return createNewSwapchainAndSwapchainSpecificStuff(); return createNewSwapchainAndSwapchainSpecificStuff();
@ -1116,8 +1139,8 @@ static SDL_bool render(void)
getVulkanResultString(result)); getVulkanResultString(result));
quit(2); quit(2);
} }
SDL_Vulkan_GetDrawableSize(state->windows[0], &w, &h); SDL_Vulkan_GetDrawableSize(vulkanContext->window, &w, &h);
if(w != (int)vulkanContext.swapchainSize.width || h != (int)vulkanContext.swapchainSize.height) if(w != (int)vulkanContext->swapchainSize.width || h != (int)vulkanContext->swapchainSize.height)
{ {
return createNewSwapchainAndSwapchainSpecificStuff(); return createNewSwapchainAndSwapchainSpecificStuff();
} }
@ -1144,7 +1167,6 @@ int main(int argc, char *argv[])
/* Set Vulkan parameters */ /* Set Vulkan parameters */
state->window_flags |= SDL_WINDOW_VULKAN; state->window_flags |= SDL_WINDOW_VULKAN;
state->num_windows = 1;
state->skip_renderer = 1; state->skip_renderer = 1;
if (!SDLTest_CommonDefaultArgs(state, argc, argv) || !SDLTest_CommonInit(state)) { if (!SDLTest_CommonDefaultArgs(state, argc, argv) || !SDLTest_CommonInit(state)) {
@ -1170,14 +1192,21 @@ int main(int argc, char *argv[])
{ {
/* Check for events */ /* Check for events */
++frames; ++frames;
while(SDL_PollEvent(&event)) while(SDL_PollEvent(&event)) /* !!! FIXME: fix coding conventions with braces and spaces */
{ {
SDLTest_CommonEvent(state, &event, &done); SDLTest_CommonEvent(state, &event, &done);
} }
if(!done) if (!done) {
int i;
for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i]) {
vulkanContext = &vulkanContexts[i];
render(); render();
} }
}
}
}
/* Print out some timing information */ /* Print out some timing information */
now = SDL_GetTicks(); now = SDL_GetTicks();