testvulkan.c File Reference
`#include <stdlib.h>`
`#include <stdio.h>`
`#include <string.h>`
`#include <math.h>`
`#include "SDL_test_common.h"`
`#include "../src/video/khronos/vulkan/vulkan.h"`
`#include "SDL_vulkan.h"`
Include dependency graph for testvulkan.c:

Go to the source code of this file.

## Data Structures

struct | VulkanContext

## Macros

#define | VK_NO_PROTOTYPES
#define | UINT64_MAX 18446744073709551615
#define | VULKAN_FUNCTIONS()
#define | VULKAN_DEVICE_FUNCTION(name) static PFN_##name name = NULL;
#define | VULKAN_GLOBAL_FUNCTION(name) static PFN_##name name = NULL;
#define | VULKAN_INSTANCE_FUNCTION(name) static PFN_##name name = NULL;
#define | VULKAN_DEVICE_FUNCTION(name)
#define | VULKAN_GLOBAL_FUNCTION(name)
#define | VULKAN_INSTANCE_FUNCTION(name)
#define | VULKAN_DEVICE_FUNCTION(name)
#define | VULKAN_GLOBAL_FUNCTION(name)
#define | VULKAN_INSTANCE_FUNCTION(name)
#define | VULKAN_DEVICE_FUNCTION(name)
#define | VULKAN_GLOBAL_FUNCTION(name)
#define | VULKAN_INSTANCE_FUNCTION(name)

## Functions

static const char * | getVulkanResultString (VkResult result)
static void | shutdownVulkan (void)
static void | quit (int rc)
static void | loadGlobalFunctions (void)
static void | createInstance (void)
static void | loadInstanceFunctions (void)
static void | createSurface (void)
static void | findPhysicalDevice (void)
static void | createDevice (void)
static void | loadDeviceFunctions (void)
static void | getQueues (void)
static void | createSemaphore (VkSemaphore *semaphore)
static void | createSemaphores (void)
static void | getSurfaceCaps (void)
static void | getSurfaceFormats (void)
static void | getSwapchainImages (void)
static SDL_bool | createSwapchain (void)
static void | destroySwapchain (void)
static void | destroyCommandBuffers (void)
static void | destroyCommandPool (void)
static void | createCommandPool (void)
static void | createCommandBuffers (void)
static void | createFences (void)
static void | destroyFences (void)
static void | recordPipelineImageBarrier (VkCommandBuffer commandBuffer, VkAccessFlags sourceAccessMask, VkAccessFlags destAccessMask, VkImageLayout sourceLayout, VkImageLayout destLayout, VkImage image)
static void | rerecordCommandBuffer (uint32_t frameIndex, const VkClearColorValue *clearColor)
static void | destroySwapchainAndSwapchainSpecificStuff (SDL_bool doDestroySwapchain)
static SDL_bool | createNewSwapchainAndSwapchainSpecificStuff (void)
static void | initVulkan (void)
static SDL_bool | render (void)
int | main (int argc, char *argv[])

## Variables

static PFN_vkGetInstanceProcAddr | vkGetInstanceProcAddr = NULL
static SDLTest_CommonState * | state
static VulkanContext | vulkanContext = {0}

## Macro Definition Documentation

## UINT64_MAX

#define UINT64_MAX 18446744073709551615

Definition at line 39 of file testvulkan.c.

Referenced by render(), and SDLTest_RandomUint64BoundaryValue().

## VK_NO_PROTOTYPES

#define VK_NO_PROTOTYPES

Definition at line 29 of file testvulkan.c.

## VULKAN_DEVICE_FUNCTION [1/4]

#define VULKAN_DEVICE_FUNCTION | ( |  | name | ) | static PFN_##name name = NULL;

Definition at line 87 of file testvulkan.c.

## VULKAN_DEVICE_FUNCTION [2/4]

#define VULKAN_DEVICE_FUNCTION | ( |  | name | ) |

Definition at line 87 of file testvulkan.c.

## VULKAN_DEVICE_FUNCTION [3/4]

#define VULKAN_DEVICE_FUNCTION | ( |  | name | ) |

Definition at line 87 of file testvulkan.c.

## VULKAN_DEVICE_FUNCTION [4/4]

#define VULKAN_DEVICE_FUNCTION | ( |  | name | ) |

Value:
name = (PFN_##name)vkGetDeviceProcAddr(vulkanContext.device, #name); \
if(!name) \
{ \
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \
"vkGetDeviceProcAddr(device, \"" #name "\") failed\n"); \
quit(2); \
}
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
vkGetDeviceProcAddr
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *pName)
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

Definition at line 87 of file testvulkan.c.

## VULKAN_FUNCTIONS

#define VULKAN_FUNCTIONS | ( |  | ) |

Definition at line 42 of file testvulkan.c.

Referenced by loadDeviceFunctions(), loadGlobalFunctions(), and loadInstanceFunctions().

## VULKAN_GLOBAL_FUNCTION [1/4]

#define VULKAN_GLOBAL_FUNCTION | ( |  | name | ) | static PFN_##name name = NULL;

Definition at line 88 of file testvulkan.c.

## VULKAN_GLOBAL_FUNCTION [2/4]

#define VULKAN_GLOBAL_FUNCTION | ( |  | name | ) |

Value:
name = (PFN_##name)vkGetInstanceProcAddr(VK_NULL_HANDLE, #name); \
if(!name) \
{ \
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \
"vkGetInstanceProcAddr(VK_NULL_HANDLE, \"" #name "\") failed\n"); \
quit(2); \
}
VK_NULL_HANDLE
#define VK_NULL_HANDLE
Definition: vulkan.h:49
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
vkGetInstanceProcAddr
static PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr
Definition: testvulkan.c:94
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

Definition at line 88 of file testvulkan.c.

## VULKAN_GLOBAL_FUNCTION [3/4]

#define VULKAN_GLOBAL_FUNCTION | ( |  | name | ) |

Definition at line 88 of file testvulkan.c.

## VULKAN_GLOBAL_FUNCTION [4/4]

#define VULKAN_GLOBAL_FUNCTION | ( |  | name | ) |

Definition at line 88 of file testvulkan.c.

## VULKAN_INSTANCE_FUNCTION [1/4]

#define VULKAN_INSTANCE_FUNCTION | ( |  | name | ) | static PFN_##name name = NULL;

Definition at line 89 of file testvulkan.c.

## VULKAN_INSTANCE_FUNCTION [2/4]

#define VULKAN_INSTANCE_FUNCTION | ( |  | name | ) |

Definition at line 89 of file testvulkan.c.

## VULKAN_INSTANCE_FUNCTION [3/4]

#define VULKAN_INSTANCE_FUNCTION | ( |  | name | ) |

Value:
name = (PFN_##name)vkGetInstanceProcAddr(vulkanContext.instance, #name); \
if(!name) \
{ \
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \
"vkGetInstanceProcAddr(instance, \"" #name "\") failed\n"); \
quit(2); \
}
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
VulkanContext::instance
VkInstance instance
Definition: testvulkan.c:178
vkGetInstanceProcAddr
static PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr
Definition: testvulkan.c:94
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

Definition at line 89 of file testvulkan.c.

## VULKAN_INSTANCE_FUNCTION [4/4]

#define VULKAN_INSTANCE_FUNCTION | ( |  | name | ) |

Definition at line 89 of file testvulkan.c.

## Function Documentation

## createCommandBuffers()

static void createCommandBuffers | ( | void |  | ) |

static

Definition at line 806 of file testvulkan.c.

References VkCommandBufferAllocateInfo::commandBufferCount, VulkanContext::commandBuffers, VulkanContext::commandPool, VkCommandBufferAllocateInfo::commandPool, VulkanContext::device, getVulkanResultString(), VkCommandBufferAllocateInfo::level, NULL, quit(), SDL_free, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_malloc, VkCommandBufferAllocateInfo::sType, VulkanContext::swapchainImageCount, VK_COMMAND_BUFFER_LEVEL_PRIMARY, VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, VK_SUCCESS, and vkAllocateCommandBuffers().

Referenced by createNewSwapchainAndSwapchainSpecificStuff().

{
VkResult result;
VkCommandBufferAllocateInfo allocateInfo = {0};
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocateInfo.commandPool = vulkanContext.commandPool;
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocateInfo.commandBufferCount = vulkanContext.swapchainImageCount;
vulkanContext.commandBuffers =
SDL_malloc(sizeof(VkCommandBuffer) * vulkanContext.swapchainImageCount);
result =
vkAllocateCommandBuffers(vulkanContext.device, &allocateInfo, vulkanContext.commandBuffers);
if(result != VK_SUCCESS)
{
SDL_free(vulkanContext.commandBuffers);
vulkanContext.commandBuffers = NULL;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkAllocateCommandBuffers(): %s\n",
getVulkanResultString(result));
quit(2);
}
}
VkCommandBufferAllocateInfo::commandPool
VkCommandPool commandPool
Definition: vulkan.h:2315
VK_COMMAND_BUFFER_LEVEL_PRIMARY
Definition: vulkan.h:951
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkResult
VkResult
Definition: vulkan.h:122
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
VkCommandBufferAllocateInfo::level
VkCommandBufferLevel level
Definition: vulkan.h:2316
VulkanContext::commandBuffers
VkCommandBuffer * commandBuffers
Definition: testvulkan.c:201
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO
Definition: vulkan.h:197
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_SUCCESS
Definition: vulkan.h:123
VkCommandBufferAllocateInfo::sType
VkStructureType sType
Definition: vulkan.h:2313
VulkanContext::swapchainImageCount
uint32_t swapchainImageCount
Definition: testvulkan.c:199
vkAllocateCommandBuffers
VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, VkCommandBuffer *pCommandBuffers)
VkCommandBufferAllocateInfo
Definition: vulkan.h:2312
quit
static void quit(int rc)
Definition: testvulkan.c:211
NULL
#define NULL
Definition: begin_code.h:164
VulkanContext::commandPool
VkCommandPool commandPool
Definition: testvulkan.c:198
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
VkCommandBufferAllocateInfo::commandBufferCount
uint32_t commandBufferCount
Definition: vulkan.h:2317
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

## createCommandPool()

static void createCommandPool | ( | void |  | ) |

static

Definition at line 785 of file testvulkan.c.

References VulkanContext::commandPool, VulkanContext::device, VkCommandPoolCreateInfo::flags, getVulkanResultString(), VulkanContext::graphicsQueueFamilyIndex, NULL, VkCommandPoolCreateInfo::queueFamilyIndex, quit(), SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, VkCommandPoolCreateInfo::sType, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, VK_NULL_HANDLE, VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, VK_SUCCESS, and vkCreateCommandPool().

Referenced by createNewSwapchainAndSwapchainSpecificStuff().

{
VkResult result;
VkCommandPoolCreateInfo createInfo = {0};
createInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
createInfo.flags =
VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT | VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
createInfo.queueFamilyIndex = vulkanContext.graphicsQueueFamilyIndex;
result =
vkCreateCommandPool(vulkanContext.device, &createInfo, NULL, &vulkanContext.commandPool);
if(result != VK_SUCCESS)
{
vulkanContext.commandPool = VK_NULL_HANDLE;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkCreateCommandPool(): %s\n",
getVulkanResultString(result));
quit(2);
}
}
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO
Definition: vulkan.h:196
VK_NULL_HANDLE
#define VK_NULL_HANDLE
Definition: vulkan.h:49
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkResult
VkResult
Definition: vulkan.h:122
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT
Definition: vulkan.h:1330
VK_COMMAND_POOL_CREATE_TRANSIENT_BIT
Definition: vulkan.h:1329
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
VkCommandPoolCreateInfo
Definition: vulkan.h:2305
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_SUCCESS
Definition: vulkan.h:123
quit
static void quit(int rc)
Definition: testvulkan.c:211
NULL
#define NULL
Definition: begin_code.h:164
VulkanContext::commandPool
VkCommandPool commandPool
Definition: testvulkan.c:198
VkCommandPoolCreateInfo::flags
VkCommandPoolCreateFlags flags
Definition: vulkan.h:2308
VkCommandPoolCreateInfo::sType
VkStructureType sType
Definition: vulkan.h:2306
vkCreateCommandPool
VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool)
VkCommandPoolCreateInfo::queueFamilyIndex
uint32_t queueFamilyIndex
Definition: vulkan.h:2309
VulkanContext::graphicsQueueFamilyIndex
uint32_t graphicsQueueFamilyIndex
Definition: testvulkan.c:184
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

## createDevice()

static void createDevice | ( | void |  | ) |

static

Definition at line 497 of file testvulkan.c.

References VulkanContext::device, VkDeviceCreateInfo::enabledExtensionCount, getVulkanResultString(), VulkanContext::graphicsQueueFamilyIndex, NULL, VkDeviceCreateInfo::pEnabledFeatures, VulkanContext::physicalDevice, VkDeviceCreateInfo::ppEnabledExtensionNames, VkDeviceCreateInfo::pQueueCreateInfos, VkDeviceQueueCreateInfo::pQueuePriorities, VkDeviceQueueCreateInfo::queueCount, VkDeviceCreateInfo::queueCreateInfoCount, VkDeviceQueueCreateInfo::queueFamilyIndex, quit(), SDL_arraysize, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, VkDeviceQueueCreateInfo::sType, VkDeviceCreateInfo::sType, VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_NULL_HANDLE, VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, VK_SUCCESS, and vkCreateDevice().

Referenced by initVulkan().

{
VkDeviceQueueCreateInfo deviceQueueCreateInfo[1] = {0};
static const float queuePriority[] = {1.0f};
VkDeviceCreateInfo deviceCreateInfo = {0};
static const char *const deviceExtensionNames[] = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
};
VkResult result;
deviceQueueCreateInfo->sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
deviceQueueCreateInfo->queueFamilyIndex = vulkanContext.graphicsQueueFamilyIndex;
deviceQueueCreateInfo->queueCount = 1;
deviceQueueCreateInfo->pQueuePriorities = &queuePriority[0];
deviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
deviceCreateInfo.queueCreateInfoCount = 1;
deviceCreateInfo.pQueueCreateInfos = deviceQueueCreateInfo;
deviceCreateInfo.pEnabledFeatures = NULL;
deviceCreateInfo.enabledExtensionCount = SDL_arraysize(deviceExtensionNames);
deviceCreateInfo.ppEnabledExtensionNames = deviceExtensionNames;
result = vkCreateDevice(
vulkanContext.physicalDevice, &deviceCreateInfo, NULL, &vulkanContext.device);
if(result != VK_SUCCESS)
{
vulkanContext.device = VK_NULL_HANDLE;
SDL_LogError(
SDL_LOG_CATEGORY_APPLICATION, "vkCreateDevice(): %s\n", getVulkanResultString(result));
quit(2);
}
}
VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO
Definition: vulkan.h:159
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
VkDeviceQueueCreateInfo::queueFamilyIndex
uint32_t queueFamilyIndex
Definition: vulkan.h:1664
VkDeviceCreateInfo::ppEnabledExtensionNames
const char *const * ppEnabledExtensionNames
Definition: vulkan.h:1678
VkDeviceQueueCreateInfo::sType
VkStructureType sType
Definition: vulkan.h:1661
VK_KHR_SWAPCHAIN_EXTENSION_NAME
#define VK_KHR_SWAPCHAIN_EXTENSION_NAME
Definition: vulkan.h:3538
VkDeviceQueueCreateInfo::queueCount
uint32_t queueCount
Definition: vulkan.h:1665
VK_NULL_HANDLE
#define VK_NULL_HANDLE
Definition: vulkan.h:49
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkResult
VkResult
Definition: vulkan.h:122
VkDeviceCreateInfo::queueCreateInfoCount
uint32_t queueCreateInfoCount
Definition: vulkan.h:1673
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
VkDeviceQueueCreateInfo
Definition: vulkan.h:1660
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
VkDeviceCreateInfo::sType
VkStructureType sType
Definition: vulkan.h:1670
VkDeviceCreateInfo::pEnabledFeatures
const VkPhysicalDeviceFeatures * pEnabledFeatures
Definition: vulkan.h:1679
VkDeviceCreateInfo
Definition: vulkan.h:1669
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_SUCCESS
Definition: vulkan.h:123
VkDeviceCreateInfo::enabledExtensionCount
uint32_t enabledExtensionCount
Definition: vulkan.h:1677
VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
Definition: vulkan.h:160
VkDeviceCreateInfo::pQueueCreateInfos
const VkDeviceQueueCreateInfo * pQueueCreateInfos
Definition: vulkan.h:1674
quit
static void quit(int rc)
Definition: testvulkan.c:211
NULL
#define NULL
Definition: begin_code.h:164
vkCreateDevice
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDevice *pDevice)
VkDeviceQueueCreateInfo::pQueuePriorities
const float * pQueuePriorities
Definition: vulkan.h:1666
SDL_arraysize
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93
VulkanContext::physicalDevice
VkPhysicalDevice physicalDevice
Definition: testvulkan.c:186
VulkanContext::graphicsQueueFamilyIndex
uint32_t graphicsQueueFamilyIndex
Definition: testvulkan.c:184
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

## createFences()

static void createFences | ( | void |  | ) |

static

Definition at line 830 of file testvulkan.c.

References VulkanContext::device, VulkanContext::fences, VkFenceCreateInfo::flags, getVulkanResultString(), i, NULL, quit(), SDL_free, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_malloc, SDL_OutOfMemory, VkFenceCreateInfo::sType, VulkanContext::swapchainImageCount, VK_FENCE_CREATE_SIGNALED_BIT, VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, VK_SUCCESS, vkCreateFence(), and vkDestroyFence().

Referenced by createNewSwapchainAndSwapchainSpecificStuff().

{
uint32_t i;
vulkanContext.fences = SDL_malloc(sizeof(VkFence) * vulkanContext.swapchainImageCount);
if(!vulkanContext.fences)
{
SDL_OutOfMemory();
quit(2);
}
for(i = 0; i < vulkanContext.swapchainImageCount; i++)
{
VkResult result;
VkFenceCreateInfo createInfo = {0};
createInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
createInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
result =
vkCreateFence(vulkanContext.device, &createInfo, NULL, &vulkanContext.fences[i]);
if(result != VK_SUCCESS)
{
for(; i > 0; i--)
{
vkDestroyFence(vulkanContext.device, vulkanContext.fences[i - 1], NULL);
}
SDL_free(vulkanContext.fences);
vulkanContext.fences = NULL;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkCreateFence(): %s\n",
getVulkanResultString(result));
quit(2);
}
}
}
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
VkFenceCreateInfo::sType
VkStructureType sType
Definition: vulkan.h:1804
VK_FENCE_CREATE_SIGNALED_BIT
Definition: vulkan.h:1155
vkDestroyFence
VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator)
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkResult
VkResult
Definition: vulkan.h:122
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
VkFenceCreateInfo
Definition: vulkan.h:1803
VulkanContext::fences
VkFence * fences
Definition: testvulkan.c:202
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
vkCreateFence
VKAPI_ATTR VkResult VKAPI_CALL vkCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkFence *pFence)
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
VkFenceCreateInfo::flags
VkFenceCreateFlags flags
Definition: vulkan.h:1806
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_SUCCESS
Definition: vulkan.h:123
VulkanContext::swapchainImageCount
uint32_t swapchainImageCount
Definition: testvulkan.c:199
quit
static void quit(int rc)
Definition: testvulkan.c:211
i
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)
Definition: SDL_x11sym.h:50
NULL
#define NULL
Definition: begin_code.h:164
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
uint32_t
unsigned int uint32_t
Definition: SDL_config_windows.h:63
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
Definition: vulkan.h:165
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

## createInstance()

static void createInstance | ( | void |  | ) |

static

Definition at line 245 of file testvulkan.c.

References VkApplicationInfo::apiVersion, VkInstanceCreateInfo::enabledExtensionCount, getVulkanResultString(), VulkanContext::instance, NULL, VkInstanceCreateInfo::pApplicationInfo, VkInstanceCreateInfo::ppEnabledExtensionNames, quit(), SDL_free, SDL_GetError, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_malloc, SDL_OutOfMemory, SDL_Vulkan_GetInstanceExtensions, VkApplicationInfo::sType, VkInstanceCreateInfo::sType, VK_API_VERSION_1_0, VK_NULL_HANDLE, VK_STRUCTURE_TYPE_APPLICATION_INFO, VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, VK_SUCCESS, vkCreateInstance(), and SDLTest_CommonState::windows.

Referenced by initVulkan().

{
VkApplicationInfo appInfo = {0};
VkInstanceCreateInfo instanceCreateInfo = {0};
const char **extensions = NULL;
unsigned extensionCount = 0;
VkResult result;
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.apiVersion = VK_API_VERSION_1_0;
instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
instanceCreateInfo.pApplicationInfo = &appInfo;
if(!SDL_Vulkan_GetInstanceExtensions(state->windows[0], &extensionCount, NULL))
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_Vulkan_GetInstanceExtensions(): %s\n",
SDL_GetError());
quit(2);
}
extensions = SDL_malloc(sizeof(const char *) * extensionCount);
if(!extensions)
{
SDL_OutOfMemory();
quit(2);
}
if(!SDL_Vulkan_GetInstanceExtensions(state->windows[0], &extensionCount, extensions))
{
SDL_free((void*)extensions);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_Vulkan_GetInstanceExtensions(): %s\n",
SDL_GetError());
quit(2);
}
instanceCreateInfo.enabledExtensionCount = extensionCount;
instanceCreateInfo.ppEnabledExtensionNames = extensions;
result = vkCreateInstance(&instanceCreateInfo, NULL, &vulkanContext.instance);
SDL_free((void*)extensions);
if(result != VK_SUCCESS)
{
vulkanContext.instance = VK_NULL_HANDLE;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkCreateInstance(): %s\n",
getVulkanResultString(result));
quit(2);
}
}
SDL_GetError
#define SDL_GetError
Definition: SDL_dynapi_overrides.h:113
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
VkInstanceCreateInfo::pApplicationInfo
const VkApplicationInfo * pApplicationInfo
Definition: vulkan.h:1383
VkInstanceCreateInfo::enabledExtensionCount
uint32_t enabledExtensionCount
Definition: vulkan.h:1386
VkApplicationInfo::apiVersion
uint32_t apiVersion
Definition: vulkan.h:1376
SDL_Vulkan_GetInstanceExtensions
#define SDL_Vulkan_GetInstanceExtensions
Definition: SDL_dynapi_overrides.h:635
VkInstanceCreateInfo
Definition: vulkan.h:1379
vkCreateInstance
VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkInstance *pInstance)
VK_NULL_HANDLE
#define VK_NULL_HANDLE
Definition: vulkan.h:49
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkResult
VkResult
Definition: vulkan.h:122
SDLTest_CommonState::windows
SDL_Window ** windows
Definition: SDL_test_common.h:78
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
Definition: vulkan.h:158
VK_STRUCTURE_TYPE_APPLICATION_INFO
Definition: vulkan.h:157
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
state
static SDLTest_CommonState * state
Definition: testvulkan.c:205
VulkanContext::instance
VkInstance instance
Definition: testvulkan.c:178
VkInstanceCreateInfo::sType
VkStructureType sType
Definition: vulkan.h:1380
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_SUCCESS
Definition: vulkan.h:123
VK_API_VERSION_1_0
#define VK_API_VERSION_1_0
Definition: vulkan.h:40
quit
static void quit(int rc)
Definition: testvulkan.c:211
NULL
#define NULL
Definition: begin_code.h:164
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
VkApplicationInfo
Definition: vulkan.h:1369
VkInstanceCreateInfo::ppEnabledExtensionNames
const char *const * ppEnabledExtensionNames
Definition: vulkan.h:1387
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
VkApplicationInfo::sType
VkStructureType sType
Definition: vulkan.h:1370
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

## createNewSwapchainAndSwapchainSpecificStuff()

static SDL_bool createNewSwapchainAndSwapchainSpecificStuff | ( | void |  | ) |

static

Definition at line 975 of file testvulkan.c.

References createCommandBuffers(), createCommandPool(), createFences(), createSwapchain(), destroySwapchainAndSwapchainSpecificStuff(), getSurfaceCaps(), getSurfaceFormats(), SDL_FALSE, and SDL_TRUE.

Referenced by initVulkan(), and render().

{
destroySwapchainAndSwapchainSpecificStuff(SDL_FALSE);
getSurfaceCaps();
getSurfaceFormats();
if(!createSwapchain())
return SDL_FALSE;
createCommandPool();
createCommandBuffers();
createFences();
return SDL_TRUE;
}
createCommandPool
static void createCommandPool(void)
Definition: testvulkan.c:785
SDL_TRUE
Definition: SDL_stdinc.h:142
SDL_FALSE
Definition: SDL_stdinc.h:141
createSwapchain
static SDL_bool createSwapchain(void)
Definition: testvulkan.c:687
getSurfaceFormats
static void getSurfaceFormats(void)
Definition: testvulkan.c:608
getSurfaceCaps
static void getSurfaceCaps(void)
Definition: testvulkan.c:587
createFences
static void createFences(void)
Definition: testvulkan.c:830
createCommandBuffers
static void createCommandBuffers(void)
Definition: testvulkan.c:806
destroySwapchainAndSwapchainSpecificStuff
static void destroySwapchainAndSwapchainSpecificStuff(SDL_bool doDestroySwapchain)
Definition: testvulkan.c:966

## createSemaphore()

static void createSemaphore | ( | VkSemaphore * | semaphore | ) |

static

Definition at line 564 of file testvulkan.c.

References VulkanContext::device, getVulkanResultString(), NULL, quit(), SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, VkSemaphoreCreateInfo::sType, VK_NULL_HANDLE, VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, VK_SUCCESS, and vkCreateSemaphore().

Referenced by createSemaphores().

{
VkResult result;
VkSemaphoreCreateInfo createInfo = {0};
createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
result = vkCreateSemaphore(vulkanContext.device, &createInfo, NULL, semaphore);
if(result != VK_SUCCESS)
{
*semaphore = VK_NULL_HANDLE;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkCreateSemaphore(): %s\n",
getVulkanResultString(result));
quit(2);
}
}
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
VK_NULL_HANDLE
#define VK_NULL_HANDLE
Definition: vulkan.h:49
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkSemaphoreCreateInfo::sType
VkStructureType sType
Definition: vulkan.h:1810
VkResult
VkResult
Definition: vulkan.h:122
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
VkSemaphoreCreateInfo
Definition: vulkan.h:1809
vkCreateSemaphore
VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore)
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_SUCCESS
Definition: vulkan.h:123
quit
static void quit(int rc)
Definition: testvulkan.c:211
NULL
#define NULL
Definition: begin_code.h:164
VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO
Definition: vulkan.h:166
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

## createSemaphores()

static void createSemaphores | ( | void |  | ) |

static

Definition at line 581 of file testvulkan.c.

References createSemaphore(), VulkanContext::imageAvailableSemaphore, and VulkanContext::renderingFinishedSemaphore.

Referenced by initVulkan().

{
createSemaphore(&vulkanContext.imageAvailableSemaphore);
createSemaphore(&vulkanContext.renderingFinishedSemaphore);
}
createSemaphore
static void createSemaphore(VkSemaphore *semaphore)
Definition: testvulkan.c:564
VulkanContext::renderingFinishedSemaphore
VkSemaphore renderingFinishedSemaphore
Definition: testvulkan.c:190
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VulkanContext::imageAvailableSemaphore
VkSemaphore imageAvailableSemaphore
Definition: testvulkan.c:189

## createSurface()

static void createSurface | ( | void |  | ) |

static

Definition at line 311 of file testvulkan.c.

References VulkanContext::instance, quit(), SDL_GetError, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_Vulkan_CreateSurface, VulkanContext::surface, VK_NULL_HANDLE, and SDLTest_CommonState::windows.

Referenced by initVulkan().

{
if(!SDL_Vulkan_CreateSurface(state->windows[0],
vulkanContext.instance,
&vulkanContext.surface))
{
vulkanContext.surface = VK_NULL_HANDLE;
SDL_LogError(
SDL_LOG_CATEGORY_APPLICATION, "SDL_Vulkan_CreateSurface(): %s\n", SDL_GetError());
quit(2);
}
}
SDL_GetError
#define SDL_GetError
Definition: SDL_dynapi_overrides.h:113
VulkanContext::surface
VkSurfaceKHR surface
Definition: testvulkan.c:180
SDL_Vulkan_CreateSurface
#define SDL_Vulkan_CreateSurface
Definition: SDL_dynapi_overrides.h:636
VK_NULL_HANDLE
#define VK_NULL_HANDLE
Definition: vulkan.h:49
SDLTest_CommonState::windows
SDL_Window ** windows
Definition: SDL_test_common.h:78
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
state
static SDLTest_CommonState * state
Definition: testvulkan.c:205
VulkanContext::instance
VkInstance instance
Definition: testvulkan.c:178
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
quit
static void quit(int rc)
Definition: testvulkan.c:211
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

## createSwapchain()

static SDL_bool createSwapchain | ( | void |  | ) |

static

Definition at line 687 of file testvulkan.c.

References VkSwapchainCreateInfoKHR::clipped, VkSurfaceFormatKHR::colorSpace, VkSwapchainCreateInfoKHR::compositeAlpha, VkSurfaceCapabilitiesKHR::currentTransform, VulkanContext::device, VkSurfaceFormatKHR::format, getSwapchainImages(), getVulkanResultString(), VkExtent2D::height, i, VkSwapchainCreateInfoKHR::imageArrayLayers, VkSwapchainCreateInfoKHR::imageColorSpace, VkSwapchainCreateInfoKHR::imageExtent, VkSwapchainCreateInfoKHR::imageFormat, VkSwapchainCreateInfoKHR::imageSharingMode, VkSwapchainCreateInfoKHR::imageUsage, VkSurfaceCapabilitiesKHR::maxImageCount, VkSurfaceCapabilitiesKHR::minImageCount, VkSwapchainCreateInfoKHR::minImageCount, NULL, VkSwapchainCreateInfoKHR::oldSwapchain, VkSwapchainCreateInfoKHR::presentMode, VkSwapchainCreateInfoKHR::preTransform, quit(), SDL_FALSE, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_TRUE, SDL_Vulkan_GetDrawableSize, VkSwapchainCreateInfoKHR::sType, VulkanContext::surface, VkSwapchainCreateInfoKHR::surface, VulkanContext::surfaceCapabilities, VulkanContext::surfaceFormat, VulkanContext::surfaceFormats, VulkanContext::surfaceFormatsCount, VulkanContext::swapchain, VulkanContext::swapchainDesiredImageCount, VulkanContext::swapchainSize, VK_COLORSPACE_SRGB_NONLINEAR_KHR, VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_UNDEFINED, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_NULL_HANDLE, VK_PRESENT_MODE_FIFO_KHR, VK_SHARING_MODE_EXCLUSIVE, VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, VK_SUCCESS, VK_TRUE, vkCreateSwapchainKHR(), vkDestroySwapchainKHR(), VkExtent2D::width, and SDLTest_CommonState::windows.

Referenced by createNewSwapchainAndSwapchainSpecificStuff().

{
uint32_t i;
int w, h;
VkSwapchainCreateInfoKHR createInfo = {0};
VkResult result;
// pick an image count
vulkanContext.swapchainDesiredImageCount = vulkanContext.surfaceCapabilities.minImageCount + 1;
if(vulkanContext.swapchainDesiredImageCount > vulkanContext.surfaceCapabilities.maxImageCount
&& vulkanContext.surfaceCapabilities.maxImageCount > 0)
vulkanContext.swapchainDesiredImageCount = vulkanContext.surfaceCapabilities.maxImageCount;
// pick a format
if(vulkanContext.surfaceFormatsCount == 1
&& vulkanContext.surfaceFormats[0].format == VK_FORMAT_UNDEFINED)
{
// aren't any preferred formats, so we pick
vulkanContext.surfaceFormat.colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
vulkanContext.surfaceFormat.format = VK_FORMAT_R8G8B8A8_UNORM;
}
else
{
vulkanContext.surfaceFormat = vulkanContext.surfaceFormats[0];
for(i = 0; i < vulkanContext.surfaceFormatsCount; i++)
{
if(vulkanContext.surfaceFormats[i].format == VK_FORMAT_R8G8B8A8_UNORM)
{
vulkanContext.surfaceFormat = vulkanContext.surfaceFormats[i];
break;
}
}
}
// get size
SDL_Vulkan_GetDrawableSize(state->windows[0], &w, &h);
vulkanContext.swapchainSize.width = w;
vulkanContext.swapchainSize.height = h;
if(w == 0 || h == 0)
return SDL_FALSE;
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
createInfo.surface = vulkanContext.surface;
createInfo.minImageCount = vulkanContext.swapchainDesiredImageCount;
createInfo.imageFormat = vulkanContext.surfaceFormat.format;
createInfo.imageColorSpace = vulkanContext.surfaceFormat.colorSpace;
createInfo.imageExtent = vulkanContext.swapchainSize;
createInfo.imageArrayLayers = 1;
createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
createInfo.preTransform = vulkanContext.surfaceCapabilities.currentTransform;
createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
createInfo.presentMode = VK_PRESENT_MODE_FIFO_KHR;
createInfo.clipped = VK_TRUE;
createInfo.oldSwapchain = vulkanContext.swapchain;
result =
vkCreateSwapchainKHR(vulkanContext.device, &createInfo, NULL, &vulkanContext.swapchain);
if(createInfo.oldSwapchain)
vkDestroySwapchainKHR(vulkanContext.device, createInfo.oldSwapchain, NULL);
if(result != VK_SUCCESS)
{
vulkanContext.swapchain = VK_NULL_HANDLE;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkCreateSwapchainKHR(): %s\n",
getVulkanResultString(result));
quit(2);
}
getSwapchainImages();
return SDL_TRUE;
}
VkSurfaceFormatKHR::format
VkFormat format
Definition: vulkan.h:3493
SDL_Vulkan_GetDrawableSize
#define SDL_Vulkan_GetDrawableSize
Definition: SDL_dynapi_overrides.h:637
VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR
Definition: vulkan.h:3471
VK_PRESENT_MODE_FIFO_KHR
Definition: vulkan.h:3445
VulkanContext::surface
VkSurfaceKHR surface
Definition: testvulkan.c:180
SDL_TRUE
Definition: SDL_stdinc.h:142
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
VkSwapchainCreateInfoKHR::sType
VkStructureType sType
Definition: vulkan.h:3548
VkSwapchainCreateInfoKHR
Definition: vulkan.h:3547
VK_SHARING_MODE_EXCLUSIVE
Definition: vulkan.h:604
VulkanContext::swapchainSize
VkExtent2D swapchainSize
Definition: testvulkan.c:197
SDL_FALSE
Definition: SDL_stdinc.h:141
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
VulkanContext::surfaceFormat
VkSurfaceFormatKHR surfaceFormat
Definition: testvulkan.c:196
vkCreateSwapchainKHR
VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain)
VkSwapchainCreateInfoKHR::preTransform
VkSurfaceTransformFlagBitsKHR preTransform
Definition: vulkan.h:3561
VulkanContext::swapchainDesiredImageCount
uint32_t swapchainDesiredImageCount
Definition: testvulkan.c:195
VkSwapchainCreateInfoKHR::imageFormat
VkFormat imageFormat
Definition: vulkan.h:3553
VkSwapchainCreateInfoKHR::surface
VkSurfaceKHR surface
Definition: vulkan.h:3551
VkSwapchainCreateInfoKHR::clipped
VkBool32 clipped
Definition: vulkan.h:3564
VkSwapchainCreateInfoKHR::oldSwapchain
VkSwapchainKHR oldSwapchain
Definition: vulkan.h:3565
VK_COLORSPACE_SRGB_NONLINEAR_KHR
#define VK_COLORSPACE_SRGB_NONLINEAR_KHR
Definition: vulkan.h:3417
VkSwapchainCreateInfoKHR::imageArrayLayers
uint32_t imageArrayLayers
Definition: vulkan.h:3556
VK_IMAGE_USAGE_TRANSFER_DST_BIT
Definition: vulkan.h:1044
VkSwapchainCreateInfoKHR::compositeAlpha
VkCompositeAlphaFlagBitsKHR compositeAlpha
Definition: vulkan.h:3562
VK_FORMAT_R8G8B8A8_UNORM
Definition: vulkan.h:400
VK_NULL_HANDLE
#define VK_NULL_HANDLE
Definition: vulkan.h:49
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkResult
VkResult
Definition: vulkan.h:122
SDLTest_CommonState::windows
SDL_Window ** windows
Definition: SDL_test_common.h:78
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
state
static SDLTest_CommonState * state
Definition: testvulkan.c:205
VkSurfaceFormatKHR::colorSpace
VkColorSpaceKHR colorSpace
Definition: vulkan.h:3494
VulkanContext::surfaceFormats
VkSurfaceFormatKHR * surfaceFormats
Definition: testvulkan.c:192
getSwapchainImages
static void getSwapchainImages(void)
Definition: testvulkan.c:649
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
Definition: vulkan.h:1047
VkSurfaceCapabilitiesKHR::currentTransform
VkSurfaceTransformFlagBitsKHR currentTransform
Definition: vulkan.h:3487
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
VkSwapchainCreateInfoKHR::imageUsage
VkImageUsageFlags imageUsage
Definition: vulkan.h:3557
VK_FORMAT_UNDEFINED
Definition: vulkan.h:363
VulkanContext::surfaceCapabilities
VkSurfaceCapabilitiesKHR surfaceCapabilities
Definition: testvulkan.c:191
VulkanContext::swapchain
VkSwapchainKHR swapchain
Definition: testvulkan.c:181
VkExtent2D::width
uint32_t width
Definition: vulkan.h:1995
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
VkSwapchainCreateInfoKHR::presentMode
VkPresentModeKHR presentMode
Definition: vulkan.h:3563
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_TRUE
#define VK_TRUE
Definition: vulkan.h:102
VK_SUCCESS
Definition: vulkan.h:123
VkSwapchainCreateInfoKHR::imageSharingMode
VkSharingMode imageSharingMode
Definition: vulkan.h:3558
quit
static void quit(int rc)
Definition: testvulkan.c:211
i
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)
Definition: SDL_x11sym.h:50
NULL
#define NULL
Definition: begin_code.h:164
uint32_t
unsigned int uint32_t
Definition: SDL_config_windows.h:63
VkSurfaceCapabilitiesKHR::maxImageCount
uint32_t maxImageCount
Definition: vulkan.h:3481
VkSwapchainCreateInfoKHR::imageColorSpace
VkColorSpaceKHR imageColorSpace
Definition: vulkan.h:3554
vkDestroySwapchainKHR
VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator)
VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR
Definition: vulkan.h:206
VkSurfaceCapabilitiesKHR::minImageCount
uint32_t minImageCount
Definition: vulkan.h:3480
VkSwapchainCreateInfoKHR::imageExtent
VkExtent2D imageExtent
Definition: vulkan.h:3555
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
VkExtent2D::height
uint32_t height
Definition: vulkan.h:1996
VkSwapchainCreateInfoKHR::minImageCount
uint32_t minImageCount
Definition: vulkan.h:3552
VulkanContext::surfaceFormatsCount
uint32_t surfaceFormatsCount
Definition: testvulkan.c:194

## destroyCommandBuffers()

static void destroyCommandBuffers | ( | void |  | ) |

static

Definition at line 767 of file testvulkan.c.

References VulkanContext::commandBuffers, VulkanContext::commandPool, VulkanContext::device, NULL, SDL_free, VulkanContext::swapchainImageCount, and vkFreeCommandBuffers().

Referenced by destroySwapchainAndSwapchainSpecificStuff().

{
if(vulkanContext.commandBuffers)
vkFreeCommandBuffers(vulkanContext.device,
vulkanContext.commandPool,
vulkanContext.swapchainImageCount,
vulkanContext.commandBuffers);
SDL_free(vulkanContext.commandBuffers);
vulkanContext.commandBuffers = NULL;
}
VulkanContext::commandBuffers
VkCommandBuffer * commandBuffers
Definition: testvulkan.c:201
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VulkanContext::swapchainImageCount
uint32_t swapchainImageCount
Definition: testvulkan.c:199
NULL
#define NULL
Definition: begin_code.h:164
vkFreeCommandBuffers
VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers)
VulkanContext::commandPool
VkCommandPool commandPool
Definition: testvulkan.c:198

## destroyCommandPool()

static void destroyCommandPool | ( | void |  | ) |

static

Definition at line 778 of file testvulkan.c.

References VulkanContext::commandPool, VulkanContext::device, NULL, VK_NULL_HANDLE, and vkDestroyCommandPool().

Referenced by destroySwapchainAndSwapchainSpecificStuff().

{
if(vulkanContext.commandPool)
vkDestroyCommandPool(vulkanContext.device, vulkanContext.commandPool, NULL);
vulkanContext.commandPool = VK_NULL_HANDLE;
}
vkDestroyCommandPool
VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator)
VK_NULL_HANDLE
#define VK_NULL_HANDLE
Definition: vulkan.h:49
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
NULL
#define NULL
Definition: begin_code.h:164
VulkanContext::commandPool
VkCommandPool commandPool
Definition: testvulkan.c:198

## destroyFences()

static void destroyFences | ( | void |  | ) |

static

Definition at line 865 of file testvulkan.c.

References VulkanContext::device, VulkanContext::fences, i, NULL, SDL_free, VulkanContext::swapchainImageCount, and vkDestroyFence().

Referenced by destroySwapchainAndSwapchainSpecificStuff().

{
uint32_t i;
if(!vulkanContext.fences)
return;
for(i = 0; i < vulkanContext.swapchainImageCount; i++)
{
vkDestroyFence(vulkanContext.device, vulkanContext.fences[i], NULL);
}
SDL_free(vulkanContext.fences);
vulkanContext.fences = NULL;
}
vkDestroyFence
VKAPI_ATTR void VKAPI_CALL vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator)
VulkanContext::fences
VkFence * fences
Definition: testvulkan.c:202
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VulkanContext::swapchainImageCount
uint32_t swapchainImageCount
Definition: testvulkan.c:199
i
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)
Definition: SDL_x11sym.h:50
NULL
#define NULL
Definition: begin_code.h:164
uint32_t
unsigned int uint32_t
Definition: SDL_config_windows.h:63

## destroySwapchain()

static void destroySwapchain | ( | void |  | ) |

static

Definition at line 758 of file testvulkan.c.

References VulkanContext::device, NULL, SDL_free, VulkanContext::swapchain, VulkanContext::swapchainImages, VK_NULL_HANDLE, and vkDestroySwapchainKHR().

Referenced by destroySwapchainAndSwapchainSpecificStuff().

{
if(vulkanContext.swapchain)
vkDestroySwapchainKHR(vulkanContext.device, vulkanContext.swapchain, NULL);
vulkanContext.swapchain = VK_NULL_HANDLE;
SDL_free(vulkanContext.swapchainImages);
vulkanContext.swapchainImages = NULL;
}
VK_NULL_HANDLE
#define VK_NULL_HANDLE
Definition: vulkan.h:49
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
VulkanContext::swapchain
VkSwapchainKHR swapchain
Definition: testvulkan.c:181
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
NULL
#define NULL
Definition: begin_code.h:164
vkDestroySwapchainKHR
VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator)
VulkanContext::swapchainImages
VkImage * swapchainImages
Definition: testvulkan.c:200

## destroySwapchainAndSwapchainSpecificStuff()

static void destroySwapchainAndSwapchainSpecificStuff | ( | SDL_bool | doDestroySwapchain | ) |

static

Definition at line 966 of file testvulkan.c.

References destroyCommandBuffers(), destroyCommandPool(), destroyFences(), and destroySwapchain().

Referenced by createNewSwapchainAndSwapchainSpecificStuff(), and shutdownVulkan().

{
destroyFences();
destroyCommandBuffers();
destroyCommandPool();
if(doDestroySwapchain)
destroySwapchain();
}
destroyCommandPool
static void destroyCommandPool(void)
Definition: testvulkan.c:778
destroySwapchain
static void destroySwapchain(void)
Definition: testvulkan.c:758
destroyCommandBuffers
static void destroyCommandBuffers(void)
Definition: testvulkan.c:767
destroyFences
static void destroyFences(void)
Definition: testvulkan.c:865

## findPhysicalDevice()

static void findPhysicalDevice | ( | void |  | ) |

static

Definition at line 324 of file testvulkan.c.

References VkPhysicalDeviceProperties::apiVersion, getVulkanResultString(), VulkanContext::graphicsQueueFamilyIndex, i, VulkanContext::instance, NULL, VulkanContext::physicalDevice, VulkanContext::physicalDeviceFeatures, VulkanContext::physicalDeviceProperties, VulkanContext::presentQueueFamilyIndex, quit(), SDL_FALSE, SDL_free, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_malloc, SDL_OutOfMemory, SDL_strcmp, SDL_TRUE, VulkanContext::surface, VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_QUEUE_GRAPHICS_BIT, VK_SUCCESS, VK_VERSION_MAJOR, vkEnumerateDeviceExtensionProperties(), vkEnumeratePhysicalDevices(), vkGetPhysicalDeviceFeatures(), vkGetPhysicalDeviceProperties(), vkGetPhysicalDeviceQueueFamilyProperties(), and vkGetPhysicalDeviceSurfaceSupportKHR().

Referenced by initVulkan().

{
uint32_t physicalDeviceCount = 0;
VkPhysicalDevice *physicalDevices;
VkQueueFamilyProperties *queueFamiliesProperties = NULL;
uint32_t queueFamiliesPropertiesAllocatedSize = 0;
VkExtensionProperties *deviceExtensions = NULL;
uint32_t deviceExtensionsAllocatedSize = 0;
uint32_t physicalDeviceIndex;
VkResult result =
vkEnumeratePhysicalDevices(vulkanContext.instance, &physicalDeviceCount, NULL);
if(result != VK_SUCCESS)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkEnumeratePhysicalDevices(): %s\n",
getVulkanResultString(result));
quit(2);
}
if(physicalDeviceCount == 0)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkEnumeratePhysicalDevices(): no physical devices\n");
quit(2);
}
physicalDevices = SDL_malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount);
if(!physicalDevices)
{
SDL_OutOfMemory();
quit(2);
}
result =
vkEnumeratePhysicalDevices(vulkanContext.instance, &physicalDeviceCount, physicalDevices);
if(result != VK_SUCCESS)
{
SDL_free(physicalDevices);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkEnumeratePhysicalDevices(): %s\n",
getVulkanResultString(result));
quit(2);
}
vulkanContext.physicalDevice = NULL;
for(physicalDeviceIndex = 0; physicalDeviceIndex < physicalDeviceCount;
physicalDeviceIndex++)
{
uint32_t queueFamiliesCount = 0;
uint32_t queueFamilyIndex;
uint32_t deviceExtensionCount = 0;
SDL_bool hasSwapchainExtension = SDL_FALSE;
uint32_t i;
VkPhysicalDevice physicalDevice = physicalDevices[physicalDeviceIndex];
vkGetPhysicalDeviceProperties(physicalDevice, &vulkanContext.physicalDeviceProperties);
if(VK_VERSION_MAJOR(vulkanContext.physicalDeviceProperties.apiVersion) < 1)
continue;
vkGetPhysicalDeviceFeatures(physicalDevice, &vulkanContext.physicalDeviceFeatures);
vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamiliesCount, NULL);
if(queueFamiliesCount == 0)
continue;
if(queueFamiliesPropertiesAllocatedSize < queueFamiliesCount)
{
SDL_free(queueFamiliesProperties);
queueFamiliesPropertiesAllocatedSize = queueFamiliesCount;
queueFamiliesProperties =
SDL_malloc(sizeof(VkQueueFamilyProperties) * queueFamiliesPropertiesAllocatedSize);
if(!queueFamiliesProperties)
{
SDL_free(physicalDevices);
SDL_free(deviceExtensions);
SDL_OutOfMemory();
quit(2);
}
}
vkGetPhysicalDeviceQueueFamilyProperties(
physicalDevice, &queueFamiliesCount, queueFamiliesProperties);
vulkanContext.graphicsQueueFamilyIndex = queueFamiliesCount;
vulkanContext.presentQueueFamilyIndex = queueFamiliesCount;
for(queueFamilyIndex = 0; queueFamilyIndex < queueFamiliesCount;
queueFamilyIndex++)
{
VkBool32 supported = 0;
if(queueFamiliesProperties[queueFamilyIndex].queueCount == 0)
continue;
if(queueFamiliesProperties[queueFamilyIndex].queueFlags & VK_QUEUE_GRAPHICS_BIT)
vulkanContext.graphicsQueueFamilyIndex = queueFamilyIndex;
result = vkGetPhysicalDeviceSurfaceSupportKHR(
physicalDevice, queueFamilyIndex, vulkanContext.surface, &supported);
if(result != VK_SUCCESS)
{
SDL_free(physicalDevices);
SDL_free(queueFamiliesProperties);
SDL_free(deviceExtensions);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkGetPhysicalDeviceSurfaceSupportKHR(): %s\n",
getVulkanResultString(result));
quit(2);
}
if(supported)
{
vulkanContext.presentQueueFamilyIndex = queueFamilyIndex;
if(queueFamiliesProperties[queueFamilyIndex].queueFlags & VK_QUEUE_GRAPHICS_BIT)
break; // use this queue because it can present and do graphics
}
}
if(vulkanContext.graphicsQueueFamilyIndex == queueFamiliesCount) // no good queues found
continue;
if(vulkanContext.presentQueueFamilyIndex == queueFamiliesCount) // no good queues found
continue;
result =
vkEnumerateDeviceExtensionProperties(physicalDevice, NULL, &deviceExtensionCount, NULL);
if(result != VK_SUCCESS)
{
SDL_free(physicalDevices);
SDL_free(queueFamiliesProperties);
SDL_free(deviceExtensions);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkEnumerateDeviceExtensionProperties(): %s\n",
getVulkanResultString(result));
quit(2);
}
if(deviceExtensionCount == 0)
continue;
if(deviceExtensionsAllocatedSize < deviceExtensionCount)
{
SDL_free(deviceExtensions);
deviceExtensionsAllocatedSize = deviceExtensionCount;
deviceExtensions =
SDL_malloc(sizeof(VkExtensionProperties) * deviceExtensionsAllocatedSize);
if(!deviceExtensions)
{
SDL_free(physicalDevices);
SDL_free(queueFamiliesProperties);
SDL_OutOfMemory();
quit(2);
}
}
result = vkEnumerateDeviceExtensionProperties(
physicalDevice, NULL, &deviceExtensionCount, deviceExtensions);
if(result != VK_SUCCESS)
{
SDL_free(physicalDevices);
SDL_free(queueFamiliesProperties);
SDL_free(deviceExtensions);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkEnumerateDeviceExtensionProperties(): %s\n",
getVulkanResultString(result));
quit(2);
}
for(i = 0; i < deviceExtensionCount; i++)
{
if(0 == SDL_strcmp(deviceExtensions[i].extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME))
{
hasSwapchainExtension = SDL_TRUE;
break;
}
}
if(!hasSwapchainExtension)
continue;
vulkanContext.physicalDevice = physicalDevice;
break;
}
SDL_free(physicalDevices);
SDL_free(queueFamiliesProperties);
SDL_free(deviceExtensions);
if(!vulkanContext.physicalDevice)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Vulkan: no viable physical devices found");
quit(2);
}
}
VulkanContext::surface
VkSurfaceKHR surface
Definition: testvulkan.c:180
SDL_TRUE
Definition: SDL_stdinc.h:142
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
vkGetPhysicalDeviceQueueFamilyProperties
VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties *pQueueFamilyProperties)
vkGetPhysicalDeviceProperties
VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties)
vkGetPhysicalDeviceSurfaceSupportKHR
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, VkSurfaceKHR surface, VkBool32 *pSupported)
SDL_FALSE
Definition: SDL_stdinc.h:141
VkExtensionProperties
Definition: vulkan.h:1682
VkBool32
uint32_t VkBool32
Definition: vulkan.h:67
VK_KHR_SWAPCHAIN_EXTENSION_NAME
#define VK_KHR_SWAPCHAIN_EXTENSION_NAME
Definition: vulkan.h:3538
vkGetPhysicalDeviceFeatures
VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures *pFeatures)
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkResult
VkResult
Definition: vulkan.h:122
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
VulkanContext::physicalDeviceProperties
VkPhysicalDeviceProperties physicalDeviceProperties
Definition: testvulkan.c:182
vkEnumeratePhysicalDevices
VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, VkPhysicalDevice *pPhysicalDevices)
VulkanContext::instance
VkInstance instance
Definition: testvulkan.c:178
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
VkQueueFamilyProperties
Definition: vulkan.h:1635
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_SUCCESS
Definition: vulkan.h:123
quit
static void quit(int rc)
Definition: testvulkan.c:211
i
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)
Definition: SDL_x11sym.h:50
NULL
#define NULL
Definition: begin_code.h:164
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:139
uint32_t
unsigned int uint32_t
Definition: SDL_config_windows.h:63
VkPhysicalDeviceProperties::apiVersion
uint32_t apiVersion
Definition: vulkan.h:1624
VK_QUEUE_GRAPHICS_BIT
Definition: vulkan.h:1080
vkEnumerateDeviceExtensionProperties
VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties)
VulkanContext::physicalDeviceFeatures
VkPhysicalDeviceFeatures physicalDeviceFeatures
Definition: testvulkan.c:183
VK_VERSION_MAJOR
#define VK_VERSION_MAJOR(version)
Definition: vulkan.h:42
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:417
VulkanContext::physicalDevice
VkPhysicalDevice physicalDevice
Definition: testvulkan.c:186
VulkanContext::presentQueueFamilyIndex
uint32_t presentQueueFamilyIndex
Definition: testvulkan.c:185
VulkanContext::graphicsQueueFamilyIndex
uint32_t graphicsQueueFamilyIndex
Definition: testvulkan.c:184
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

## getQueues()

static void getQueues | ( | void |  | ) |

static

Definition at line 549 of file testvulkan.c.

References VulkanContext::device, VulkanContext::graphicsQueue, VulkanContext::graphicsQueueFamilyIndex, VulkanContext::presentQueue, VulkanContext::presentQueueFamilyIndex, and vkGetDeviceQueue().

Referenced by initVulkan().

{
vkGetDeviceQueue(vulkanContext.device,
vulkanContext.graphicsQueueFamilyIndex,
0,
&vulkanContext.graphicsQueue);
if(vulkanContext.graphicsQueueFamilyIndex != vulkanContext.presentQueueFamilyIndex)
vkGetDeviceQueue(vulkanContext.device,
vulkanContext.presentQueueFamilyIndex,
0,
&vulkanContext.presentQueue);
else
vulkanContext.presentQueue = vulkanContext.graphicsQueue;
}
VulkanContext::presentQueue
VkQueue presentQueue
Definition: testvulkan.c:188
vkGetDeviceQueue
VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue)
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VulkanContext::graphicsQueue
VkQueue graphicsQueue
Definition: testvulkan.c:187
VulkanContext::presentQueueFamilyIndex
uint32_t presentQueueFamilyIndex
Definition: testvulkan.c:185
VulkanContext::graphicsQueueFamilyIndex
uint32_t graphicsQueueFamilyIndex
Definition: testvulkan.c:184

## getSurfaceCaps()

static void getSurfaceCaps | ( | void |  | ) |

static

Definition at line 587 of file testvulkan.c.

References getVulkanResultString(), VulkanContext::physicalDevice, quit(), SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, VkSurfaceCapabilitiesKHR::supportedUsageFlags, VulkanContext::surface, VulkanContext::surfaceCapabilities, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_SUCCESS, and vkGetPhysicalDeviceSurfaceCapabilitiesKHR().

Referenced by createNewSwapchainAndSwapchainSpecificStuff().

{
VkResult result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
vulkanContext.physicalDevice, vulkanContext.surface, &vulkanContext.surfaceCapabilities);
if(result != VK_SUCCESS)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): %s\n",
getVulkanResultString(result));
quit(2);
}
// check surface usage
if(!(vulkanContext.surfaceCapabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT))
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Vulkan surface doesn't support VK_IMAGE_USAGE_TRANSFER_DST_BIT\n");
quit(2);
}
}
VulkanContext::surface
VkSurfaceKHR surface
Definition: testvulkan.c:180
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
VK_IMAGE_USAGE_TRANSFER_DST_BIT
Definition: vulkan.h:1044
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkResult
VkResult
Definition: vulkan.h:122
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
VulkanContext::surfaceCapabilities
VkSurfaceCapabilitiesKHR surfaceCapabilities
Definition: testvulkan.c:191
VkSurfaceCapabilitiesKHR::supportedUsageFlags
VkImageUsageFlags supportedUsageFlags
Definition: vulkan.h:3489
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_SUCCESS
Definition: vulkan.h:123
quit
static void quit(int rc)
Definition: testvulkan.c:211
vkGetPhysicalDeviceSurfaceCapabilitiesKHR
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities)
VulkanContext::physicalDevice
VkPhysicalDevice physicalDevice
Definition: testvulkan.c:186
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

## getSurfaceFormats()

static void getSurfaceFormats | ( | void |  | ) |

static

Definition at line 608 of file testvulkan.c.

References getVulkanResultString(), NULL, VulkanContext::physicalDevice, quit(), SDL_free, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_malloc, SDL_OutOfMemory, VulkanContext::surface, VulkanContext::surfaceFormats, VulkanContext::surfaceFormatsAllocatedCount, VulkanContext::surfaceFormatsCount, VK_SUCCESS, and vkGetPhysicalDeviceSurfaceFormatsKHR().

Referenced by createNewSwapchainAndSwapchainSpecificStuff().

{
VkResult result = vkGetPhysicalDeviceSurfaceFormatsKHR(vulkanContext.physicalDevice,
vulkanContext.surface,
&vulkanContext.surfaceFormatsCount,
NULL);
if(result != VK_SUCCESS)
{
vulkanContext.surfaceFormatsCount = 0;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkGetPhysicalDeviceSurfaceFormatsKHR(): %s\n",
getVulkanResultString(result));
quit(2);
}
if(vulkanContext.surfaceFormatsCount > vulkanContext.surfaceFormatsAllocatedCount)
{
vulkanContext.surfaceFormatsAllocatedCount = vulkanContext.surfaceFormatsCount;
SDL_free(vulkanContext.surfaceFormats);
vulkanContext.surfaceFormats =
SDL_malloc(sizeof(VkSurfaceFormatKHR) * vulkanContext.surfaceFormatsAllocatedCount);
if(!vulkanContext.surfaceFormats)
{
vulkanContext.surfaceFormatsCount = 0;
SDL_OutOfMemory();
quit(2);
}
}
result = vkGetPhysicalDeviceSurfaceFormatsKHR(vulkanContext.physicalDevice,
vulkanContext.surface,
&vulkanContext.surfaceFormatsCount,
vulkanContext.surfaceFormats);
if(result != VK_SUCCESS)
{
vulkanContext.surfaceFormatsCount = 0;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkGetPhysicalDeviceSurfaceFormatsKHR(): %s\n",
getVulkanResultString(result));
quit(2);
}
}
VulkanContext::surface
VkSurfaceKHR surface
Definition: testvulkan.c:180
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkResult
VkResult
Definition: vulkan.h:122
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
VulkanContext::surfaceFormats
VkSurfaceFormatKHR * surfaceFormats
Definition: testvulkan.c:192
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
vkGetPhysicalDeviceSurfaceFormatsKHR
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t *pSurfaceFormatCount, VkSurfaceFormatKHR *pSurfaceFormats)
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_SUCCESS
Definition: vulkan.h:123
quit
static void quit(int rc)
Definition: testvulkan.c:211
NULL
#define NULL
Definition: begin_code.h:164
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
VulkanContext::physicalDevice
VkPhysicalDevice physicalDevice
Definition: testvulkan.c:186
VulkanContext::surfaceFormatsAllocatedCount
uint32_t surfaceFormatsAllocatedCount
Definition: testvulkan.c:193
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
VkSurfaceFormatKHR
Definition: vulkan.h:3492
VulkanContext::surfaceFormatsCount
uint32_t surfaceFormatsCount
Definition: testvulkan.c:194

## getSwapchainImages()

static void getSwapchainImages | ( | void |  | ) |

static

Definition at line 649 of file testvulkan.c.

References VulkanContext::device, getVulkanResultString(), NULL, quit(), SDL_free, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_malloc, SDL_OutOfMemory, VulkanContext::swapchain, VulkanContext::swapchainImageCount, VulkanContext::swapchainImages, VK_SUCCESS, and vkGetSwapchainImagesKHR().

Referenced by createSwapchain().

{
VkResult result;
SDL_free(vulkanContext.swapchainImages);
vulkanContext.swapchainImages = NULL;
result = vkGetSwapchainImagesKHR(
vulkanContext.device, vulkanContext.swapchain, &vulkanContext.swapchainImageCount, NULL);
if(result != VK_SUCCESS)
{
vulkanContext.swapchainImageCount = 0;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkGetSwapchainImagesKHR(): %s\n",
getVulkanResultString(result));
quit(2);
}
vulkanContext.swapchainImages = SDL_malloc(sizeof(VkImage) * vulkanContext.swapchainImageCount);
if(!vulkanContext.swapchainImages)
{
SDL_OutOfMemory();
quit(2);
}
result = vkGetSwapchainImagesKHR(vulkanContext.device,
vulkanContext.swapchain,
&vulkanContext.swapchainImageCount,
vulkanContext.swapchainImages);
if(result != VK_SUCCESS)
{
SDL_free(vulkanContext.swapchainImages);
vulkanContext.swapchainImages = NULL;
vulkanContext.swapchainImageCount = 0;
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkGetSwapchainImagesKHR(): %s\n",
getVulkanResultString(result));
quit(2);
}
}
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkResult
VkResult
Definition: vulkan.h:122
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
vkGetSwapchainImagesKHR
VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages)
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
VulkanContext::swapchain
VkSwapchainKHR swapchain
Definition: testvulkan.c:181
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_SUCCESS
Definition: vulkan.h:123
VulkanContext::swapchainImageCount
uint32_t swapchainImageCount
Definition: testvulkan.c:199
quit
static void quit(int rc)
Definition: testvulkan.c:211
NULL
#define NULL
Definition: begin_code.h:164
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
VulkanContext::swapchainImages
VkImage * swapchainImages
Definition: testvulkan.c:200

## getVulkanResultString()

static const char* getVulkanResultString | ( | VkResult | result | ) |

static

Definition at line 111 of file testvulkan.c.

References VK_ERROR_DEVICE_LOST, VK_ERROR_EXTENSION_NOT_PRESENT, VK_ERROR_FEATURE_NOT_PRESENT, VK_ERROR_FORMAT_NOT_SUPPORTED, VK_ERROR_FRAGMENTED_POOL, VK_ERROR_INCOMPATIBLE_DISPLAY_KHR, VK_ERROR_INCOMPATIBLE_DRIVER, VK_ERROR_INITIALIZATION_FAILED, VK_ERROR_INVALID_SHADER_NV, VK_ERROR_LAYER_NOT_PRESENT, VK_ERROR_MEMORY_MAP_FAILED, VK_ERROR_NATIVE_WINDOW_IN_USE_KHR, VK_ERROR_OUT_OF_DATE_KHR, VK_ERROR_OUT_OF_DEVICE_MEMORY, VK_ERROR_OUT_OF_HOST_MEMORY, VK_ERROR_OUT_OF_POOL_MEMORY_KHR, VK_ERROR_SURFACE_LOST_KHR, VK_ERROR_TOO_MANY_OBJECTS, VK_ERROR_VALIDATION_FAILED_EXT, VK_EVENT_RESET, VK_EVENT_SET, VK_INCOMPLETE, VK_NOT_READY, VK_RESULT_MAX_ENUM, VK_RESULT_RANGE_SIZE, VK_SUBOPTIMAL_KHR, VK_SUCCESS, and VK_TIMEOUT.

Referenced by createCommandBuffers(), createCommandPool(), createDevice(), createFences(), createInstance(), createSemaphore(), createSwapchain(), findPhysicalDevice(), getSurfaceCaps(), getSurfaceFormats(), getSwapchainImages(), render(), and rerecordCommandBuffer().

{
switch((int)result)
{
case VK_SUCCESS:
return "VK_SUCCESS";
case VK_NOT_READY:
return "VK_NOT_READY";
case VK_TIMEOUT:
return "VK_TIMEOUT";
case VK_EVENT_SET:
return "VK_EVENT_SET";
case VK_EVENT_RESET:
return "VK_EVENT_RESET";
case VK_INCOMPLETE:
return "VK_INCOMPLETE";
case VK_ERROR_OUT_OF_HOST_MEMORY:
return "VK_ERROR_OUT_OF_HOST_MEMORY";
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
case VK_ERROR_INITIALIZATION_FAILED:
return "VK_ERROR_INITIALIZATION_FAILED";
case VK_ERROR_DEVICE_LOST:
return "VK_ERROR_DEVICE_LOST";
case VK_ERROR_MEMORY_MAP_FAILED:
return "VK_ERROR_MEMORY_MAP_FAILED";
case VK_ERROR_LAYER_NOT_PRESENT:
return "VK_ERROR_LAYER_NOT_PRESENT";
case VK_ERROR_EXTENSION_NOT_PRESENT:
return "VK_ERROR_EXTENSION_NOT_PRESENT";
case VK_ERROR_FEATURE_NOT_PRESENT:
return "VK_ERROR_FEATURE_NOT_PRESENT";
case VK_ERROR_INCOMPATIBLE_DRIVER:
return "VK_ERROR_INCOMPATIBLE_DRIVER";
case VK_ERROR_TOO_MANY_OBJECTS:
return "VK_ERROR_TOO_MANY_OBJECTS";
case VK_ERROR_FORMAT_NOT_SUPPORTED:
return "VK_ERROR_FORMAT_NOT_SUPPORTED";
case VK_ERROR_FRAGMENTED_POOL:
return "VK_ERROR_FRAGMENTED_POOL";
case VK_ERROR_SURFACE_LOST_KHR:
return "VK_ERROR_SURFACE_LOST_KHR";
case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:
return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
case VK_SUBOPTIMAL_KHR:
return "VK_SUBOPTIMAL_KHR";
case VK_ERROR_OUT_OF_DATE_KHR:
return "VK_ERROR_OUT_OF_DATE_KHR";
case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:
return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
case VK_ERROR_VALIDATION_FAILED_EXT:
return "VK_ERROR_VALIDATION_FAILED_EXT";
case VK_ERROR_OUT_OF_POOL_MEMORY_KHR:
return "VK_ERROR_OUT_OF_POOL_MEMORY_KHR";
case VK_ERROR_INVALID_SHADER_NV:
return "VK_ERROR_INVALID_SHADER_NV";
case VK_RESULT_MAX_ENUM:
case VK_RESULT_RANGE_SIZE:
break;
}
if(result < 0)
return "VK_ERROR_<Unknown>";
return "VK_<Unknown>";
}
VK_ERROR_NATIVE_WINDOW_IN_USE_KHR
Definition: vulkan.h:142
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
VK_ERROR_EXTENSION_NOT_PRESENT
Definition: vulkan.h:135
VK_EVENT_SET
Definition: vulkan.h:126
VK_INCOMPLETE
Definition: vulkan.h:128
VK_ERROR_OUT_OF_POOL_MEMORY_KHR
Definition: vulkan.h:148
VK_EVENT_RESET
Definition: vulkan.h:127
VK_ERROR_FORMAT_NOT_SUPPORTED
Definition: vulkan.h:139
VK_ERROR_INCOMPATIBLE_DISPLAY_KHR
Definition: vulkan.h:145
VK_ERROR_SURFACE_LOST_KHR
Definition: vulkan.h:141
VK_NOT_READY
Definition: vulkan.h:124
VK_ERROR_VALIDATION_FAILED_EXT
Definition: vulkan.h:146
VK_ERROR_FRAGMENTED_POOL
Definition: vulkan.h:140
VK_SUCCESS
Definition: vulkan.h:123
VK_TIMEOUT
Definition: vulkan.h:125
VK_ERROR_INITIALIZATION_FAILED
Definition: vulkan.h:131
VK_ERROR_OUT_OF_DATE_KHR
Definition: vulkan.h:144
VK_ERROR_INVALID_SHADER_NV
Definition: vulkan.h:147
VK_SUBOPTIMAL_KHR
Definition: vulkan.h:143
VK_ERROR_TOO_MANY_OBJECTS
Definition: vulkan.h:138
VK_RESULT_MAX_ENUM
Definition: vulkan.h:153
VK_ERROR_LAYER_NOT_PRESENT
Definition: vulkan.h:134
VK_ERROR_OUT_OF_DEVICE_MEMORY
Definition: vulkan.h:130
VK_ERROR_DEVICE_LOST
Definition: vulkan.h:132
VK_ERROR_MEMORY_MAP_FAILED
Definition: vulkan.h:133
VK_ERROR_OUT_OF_HOST_MEMORY
Definition: vulkan.h:129
VK_ERROR_INCOMPATIBLE_DRIVER
Definition: vulkan.h:137
VK_RESULT_RANGE_SIZE
Definition: vulkan.h:152
VK_ERROR_FEATURE_NOT_PRESENT
Definition: vulkan.h:136

## initVulkan()

static void initVulkan | ( | void |  | ) |

static

Definition at line 988 of file testvulkan.c.

References createDevice(), createInstance(), createNewSwapchainAndSwapchainSpecificStuff(), createSemaphores(), createSurface(), findPhysicalDevice(), getQueues(), loadDeviceFunctions(), loadGlobalFunctions(), loadInstanceFunctions(), NULL, SDL_memset, and SDL_Vulkan_LoadLibrary.

Referenced by main().

{
SDL_Vulkan_LoadLibrary(NULL);
SDL_memset(&vulkanContext, 0, sizeof(VulkanContext));
loadGlobalFunctions();
createInstance();
loadInstanceFunctions();
createSurface();
findPhysicalDevice();
createDevice();
loadDeviceFunctions();
getQueues();
createSemaphores();
createNewSwapchainAndSwapchainSpecificStuff();
}
createSemaphores
static void createSemaphores(void)
Definition: testvulkan.c:581
loadInstanceFunctions
static void loadInstanceFunctions(void)
Definition: testvulkan.c:293
loadGlobalFunctions
static void loadGlobalFunctions(void)
Definition: testvulkan.c:218
createDevice
static void createDevice(void)
Definition: testvulkan.c:497
findPhysicalDevice
static void findPhysicalDevice(void)
Definition: testvulkan.c:324
SDL_Vulkan_LoadLibrary
#define SDL_Vulkan_LoadLibrary
Definition: SDL_dynapi_overrides.h:632
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
createInstance
static void createInstance(void)
Definition: testvulkan.c:245
NULL
#define NULL
Definition: begin_code.h:164
getQueues
static void getQueues(void)
Definition: testvulkan.c:549
VulkanContext
Definition: testvulkan.c:176
loadDeviceFunctions
static void loadDeviceFunctions(void)
Definition: testvulkan.c:529
createNewSwapchainAndSwapchainSpecificStuff
static SDL_bool createNewSwapchainAndSwapchainSpecificStuff(void)
Definition: testvulkan.c:975
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:386
createSurface
static void createSurface(void)
Definition: testvulkan.c:311

## loadDeviceFunctions()

static void loadDeviceFunctions | ( | void |  | ) |

static

Definition at line 529 of file testvulkan.c.

References VULKAN_FUNCTIONS.

Referenced by initVulkan().

{
#define VULKAN_DEVICE_FUNCTION(name) \
name = (PFN_##name)vkGetDeviceProcAddr(vulkanContext.device, #name); \
if(!name) \
{ \
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \
"vkGetDeviceProcAddr(device, \"" #name "\") failed\n"); \
quit(2); \
}
#define VULKAN_GLOBAL_FUNCTION(name)
#define VULKAN_INSTANCE_FUNCTION(name)
VULKAN_FUNCTIONS()
#undef VULKAN_DEVICE_FUNCTION
#undef VULKAN_GLOBAL_FUNCTION
#undef VULKAN_INSTANCE_FUNCTION
}
VULKAN_FUNCTIONS
#define VULKAN_FUNCTIONS()
Definition: testvulkan.c:42

## loadGlobalFunctions()

static void loadGlobalFunctions | ( | void |  | ) |

static

Definition at line 218 of file testvulkan.c.

References quit(), SDL_GetError, SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_Vulkan_GetVkGetInstanceProcAddr, and VULKAN_FUNCTIONS.

Referenced by initVulkan().

{
vkGetInstanceProcAddr = SDL_Vulkan_GetVkGetInstanceProcAddr();
if(!vkGetInstanceProcAddr)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_Vulkan_GetVkGetInstanceProcAddr(): %s\n",
SDL_GetError());
quit(2);
}
#define VULKAN_DEVICE_FUNCTION(name)
#define VULKAN_GLOBAL_FUNCTION(name) \
name = (PFN_##name)vkGetInstanceProcAddr(VK_NULL_HANDLE, #name); \
if(!name) \
{ \
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \
"vkGetInstanceProcAddr(VK_NULL_HANDLE, \"" #name "\") failed\n"); \
quit(2); \
}
#define VULKAN_INSTANCE_FUNCTION(name)
VULKAN_FUNCTIONS()
#undef VULKAN_DEVICE_FUNCTION
#undef VULKAN_GLOBAL_FUNCTION
#undef VULKAN_INSTANCE_FUNCTION
}
SDL_GetError
#define SDL_GetError
Definition: SDL_dynapi_overrides.h:113
VULKAN_FUNCTIONS
#define VULKAN_FUNCTIONS()
Definition: testvulkan.c:42
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
vkGetInstanceProcAddr
static PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr
Definition: testvulkan.c:94
quit
static void quit(int rc)
Definition: testvulkan.c:211
SDL_Vulkan_GetVkGetInstanceProcAddr
#define SDL_Vulkan_GetVkGetInstanceProcAddr
Definition: SDL_dynapi_overrides.h:633
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66

## loadInstanceFunctions()

static void loadInstanceFunctions | ( | void |  | ) |

static

Definition at line 293 of file testvulkan.c.

References VULKAN_FUNCTIONS.

Referenced by initVulkan().

{
#define VULKAN_DEVICE_FUNCTION(name)
#define VULKAN_GLOBAL_FUNCTION(name)
#define VULKAN_INSTANCE_FUNCTION(name) \
name = (PFN_##name)vkGetInstanceProcAddr(vulkanContext.instance, #name); \
if(!name) \
{ \
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, \
"vkGetInstanceProcAddr(instance, \"" #name "\") failed\n"); \
quit(2); \
}
VULKAN_FUNCTIONS()
#undef VULKAN_DEVICE_FUNCTION
#undef VULKAN_GLOBAL_FUNCTION
#undef VULKAN_INSTANCE_FUNCTION
}
VULKAN_FUNCTIONS
#define VULKAN_FUNCTIONS()
Definition: testvulkan.c:42

## main()

int main | ( | int | argc,
|  | char * | argv[]
| ) |  |

Definition at line 1119 of file testvulkan.c.

References done, SDL_DisplayMode::format, i, initVulkan(), SDLTest_CommonState::num_windows, quit(), render(), SDL_BITSPERPIXEL, SDL_GetCurrentDisplayMode, SDL_GetTicks(), SDL_GetWindowSize, SDL_INIT_VIDEO, SDL_Log, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogSetPriority, SDL_PollEvent, SDL_Vulkan_GetDrawableSize, SDL_WINDOW_VULKAN, SDLTest_CommonArg(), SDLTest_CommonCreateState(), SDLTest_CommonEvent(), SDLTest_CommonInit(), SDLTest_CommonUsage(), SDLTest_CommonState::skip_renderer, SDLTest_CommonState::window_flags, and SDLTest_CommonState::windows.

{
int fsaa, accel;
int i, done;
SDL_DisplayMode mode;
SDL_Event event;
Uint32 then, now, frames;
int dw, dh;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize parameters */
fsaa = 0;
accel = -1;
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if(!state)
{
return 1;
}
for(i = 1; i < argc;)
{
int consumed;
consumed = SDLTest_CommonArg(state, i);
if(consumed < 0)
{
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
quit(1);
}
i += consumed;
}
/* Set Vulkan parameters */
state->window_flags |= SDL_WINDOW_VULKAN;
state->num_windows = 1;
state->skip_renderer = 1;
if(!SDLTest_CommonInit(state))
{
quit(2);
}
SDL_GetCurrentDisplayMode(0, &mode);
SDL_Log("Screen BPP : %d\n", SDL_BITSPERPIXEL(mode.format));
SDL_GetWindowSize(state->windows[0], &dw, &dh);
SDL_Log("Window Size : %d,%d\n", dw, dh);
SDL_Vulkan_GetDrawableSize(state->windows[0], &dw, &dh);
SDL_Log("Draw Size : %d,%d\n", dw, dh);
SDL_Log("\n");
initVulkan();
/* Main render loop */
frames = 0;
then = SDL_GetTicks();
done = 0;
while(!done)
{
/* Check for events */
++frames;
while(SDL_PollEvent(&event))
{
SDLTest_CommonEvent(state, &event, &done);
}
if(!done)
render();
}
/* Print out some timing information */
now = SDL_GetTicks();
if(now > then)
{
SDL_Log("%2.2f frames per second\n", ((double)frames * 1000) / (now - then));
}
quit(0);
return 0;
}
SDL_Vulkan_GetDrawableSize
#define SDL_Vulkan_GetDrawableSize
Definition: SDL_dynapi_overrides.h:637
SDL_PollEvent
#define SDL_PollEvent
Definition: SDL_dynapi_overrides.h:122
SDLTest_CommonState::skip_renderer
SDL_bool skip_renderer
Definition: SDL_test_common.h:83
SDLTest_CommonCreateState
SDLTest_CommonState * SDLTest_CommonCreateState(char **argv, Uint32 flags)
Parse command line parameters and create common state.
Definition: SDL_test_common.c:48
SDLTest_CommonArg
int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
Process one common argument.
Definition: SDL_test_common.c:106
SDL_DisplayMode
The structure that defines a display mode.
Definition: SDL_video.h:53
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:181
SDLTest_CommonInit
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
Open test window.
Definition: SDL_test_common.c:726
SDLTest_CommonState::windows
SDL_Window ** windows
Definition: SDL_test_common.h:78
state
static SDLTest_CommonState * state
Definition: testvulkan.c:205
SDLTest_CommonState::num_windows
int num_windows
Definition: SDL_test_common.h:77
SDL_GetWindowSize
#define SDL_GetWindowSize
Definition: SDL_dynapi_overrides.h:527
SDLTest_CommonState::window_flags
Uint32 window_flags
Definition: SDL_test_common.h:63
SDL_Log
#define SDL_Log
Definition: SDL_dynapi_overrides.h:31
SDLTest_CommonEvent
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
Common event handler for test windows.
Definition: SDL_test_common.c:1425
initVulkan
static void initVulkan(void)
Definition: testvulkan.c:988
SDL_GetTicks
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
SDL_WINDOW_VULKAN
Definition: SDL_video.h:122
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
done
int done
Definition: checkkeys.c:28
mode
GLenum mode
Definition: SDL_opengl_glext.h:1122
SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
SDLTest_CommonUsage
const char * SDLTest_CommonUsage(SDLTest_CommonState *state)
Returns common usage information.
Definition: SDL_test_common.c:478
quit
static void quit(int rc)
Definition: testvulkan.c:211
i
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)
Definition: SDL_x11sym.h:50
SDL_LogSetPriority
#define SDL_LogSetPriority
Definition: SDL_dynapi_overrides.h:236
SDL_Event
General event structure.
Definition: SDL_events.h:525
SDL_DisplayMode::format
Uint32 format
Definition: SDL_video.h:55
SDL_GetCurrentDisplayMode
#define SDL_GetCurrentDisplayMode
Definition: SDL_dynapi_overrides.h:508
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
SDL_BITSPERPIXEL
#define SDL_BITSPERPIXEL(X)
Definition: SDL_pixels.h:127
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:78
render
static SDL_bool render(void)
Definition: testvulkan.c:1023

## quit()

static void quit | ( | int | rc | ) |

static

Definition at line 211 of file testvulkan.c.

References SDLTest_CommonQuit(), and shutdownVulkan().

Referenced by createCommandBuffers(), createCommandPool(), createDevice(), createFences(), createInstance(), createSemaphore(), createSurface(), createSwapchain(), findPhysicalDevice(), getSurfaceCaps(), getSurfaceFormats(), getSwapchainImages(), loadGlobalFunctions(), main(), render(), and rerecordCommandBuffer().

{
shutdownVulkan();
SDLTest_CommonQuit(state);
exit(rc);
}
shutdownVulkan
static void shutdownVulkan(void)
Definition: testvulkan.c:1004
state
static SDLTest_CommonState * state
Definition: testvulkan.c:205
SDLTest_CommonQuit
void SDLTest_CommonQuit(SDLTest_CommonState *state)
Close test window.
Definition: SDL_test_common.c:1751

## recordPipelineImageBarrier()

static void recordPipelineImageBarrier | ( | VkCommandBuffer | commandBuffer,
|  | VkAccessFlags | sourceAccessMask,
|  | VkAccessFlags | destAccessMask,
|  | VkImageLayout | sourceLayout,
|  | VkImageLayout | destLayout,
|  | VkImage | image
| ) |  |

static

Definition at line 879 of file testvulkan.c.

References VkImageSubresourceRange::aspectMask, VkImageSubresourceRange::baseArrayLayer, VkImageSubresourceRange::baseMipLevel, VkImageMemoryBarrier::dstAccessMask, VkImageMemoryBarrier::dstQueueFamilyIndex, VkImageMemoryBarrier::image, VkImageSubresourceRange::layerCount, VkImageSubresourceRange::levelCount, VkImageMemoryBarrier::newLayout, NULL, VkImageMemoryBarrier::oldLayout, VkImageMemoryBarrier::srcAccessMask, VkImageMemoryBarrier::srcQueueFamilyIndex, VkImageMemoryBarrier::sType, VkImageMemoryBarrier::subresourceRange, VK_IMAGE_ASPECT_COLOR_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_QUEUE_FAMILY_IGNORED, VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, and vkCmdPipelineBarrier().

Referenced by rerecordCommandBuffer().

{
VkImageMemoryBarrier barrier = {0};
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.srcAccessMask = sourceAccessMask;
barrier.dstAccessMask = destAccessMask;
barrier.oldLayout = sourceLayout;
barrier.newLayout = destLayout;
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
barrier.image = image;
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
barrier.subresourceRange.baseMipLevel = 0;
barrier.subresourceRange.levelCount = 1;
barrier.subresourceRange.baseArrayLayer = 0;
barrier.subresourceRange.layerCount = 1;
vkCmdPipelineBarrier(commandBuffer,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
0,
0,
NULL,
0,
NULL,
1,
&barrier);
}
image
GLeglImageOES image
Definition: SDL_opengl.h:2148
vkCmdPipelineBarrier
VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers)
VkImageMemoryBarrier::newLayout
VkImageLayout newLayout
Definition: vulkan.h:2436
VkImageMemoryBarrier::srcAccessMask
VkAccessFlags srcAccessMask
Definition: vulkan.h:2433
VkImageMemoryBarrier::srcQueueFamilyIndex
uint32_t srcQueueFamilyIndex
Definition: vulkan.h:2437
VkImageSubresourceRange::baseMipLevel
uint32_t baseMipLevel
Definition: vulkan.h:1886
VK_IMAGE_ASPECT_COLOR_BIT
Definition: vulkan.h:1132
VkImageMemoryBarrier
Definition: vulkan.h:2430
VK_PIPELINE_STAGE_TRANSFER_BIT
Definition: vulkan.h:1120
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER
Definition: vulkan.h:202
VkImageMemoryBarrier::dstAccessMask
VkAccessFlags dstAccessMask
Definition: vulkan.h:2434
VK_QUEUE_FAMILY_IGNORED
#define VK_QUEUE_FAMILY_IGNORED
Definition: vulkan.h:104
VkImageMemoryBarrier::dstQueueFamilyIndex
uint32_t dstQueueFamilyIndex
Definition: vulkan.h:2438
VkImageMemoryBarrier::sType
VkStructureType sType
Definition: vulkan.h:2431
VkImageMemoryBarrier::subresourceRange
VkImageSubresourceRange subresourceRange
Definition: vulkan.h:2440
NULL
#define NULL
Definition: begin_code.h:164
VkImageSubresourceRange::aspectMask
VkImageAspectFlags aspectMask
Definition: vulkan.h:1885
VkImageSubresourceRange::baseArrayLayer
uint32_t baseArrayLayer
Definition: vulkan.h:1888
VkImageMemoryBarrier::oldLayout
VkImageLayout oldLayout
Definition: vulkan.h:2435
VkImageSubresourceRange::levelCount
uint32_t levelCount
Definition: vulkan.h:1887
VkImageMemoryBarrier::image
VkImage image
Definition: vulkan.h:2439
VkImageSubresourceRange::layerCount
uint32_t layerCount
Definition: vulkan.h:1889

## render()

static SDL_bool render | ( | void |  | ) |

static

Definition at line 1023 of file testvulkan.c.

References VkSubmitInfo::commandBufferCount, VulkanContext::commandBuffers, createNewSwapchainAndSwapchainSpecificStuff(), VulkanContext::device, VulkanContext::fences, VkClearColorValue::float32, getVulkanResultString(), VulkanContext::graphicsQueue, VkExtent2D::height, VulkanContext::imageAvailableSemaphore, VkSubmitInfo::pCommandBuffers, VkPresentInfoKHR::pImageIndices, VulkanContext::presentQueue, VkSubmitInfo::pSignalSemaphores, VkPresentInfoKHR::pSwapchains, VkSubmitInfo::pWaitDstStageMask, VkSubmitInfo::pWaitSemaphores, VkPresentInfoKHR::pWaitSemaphores, quit(), VulkanContext::renderingFinishedSemaphore, rerecordCommandBuffer(), retval, SDL_Delay, SDL_GetPerformanceCounter, SDL_GetPerformanceFrequency(), SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, SDL_sin, SDL_TRUE, SDL_Vulkan_GetDrawableSize, VkSubmitInfo::signalSemaphoreCount, VkSubmitInfo::sType, VkPresentInfoKHR::sType, VulkanContext::swapchain, VkPresentInfoKHR::swapchainCount, VulkanContext::swapchainSize, UINT64_MAX, VK_ERROR_OUT_OF_DATE_KHR, VK_FALSE, VK_NULL_HANDLE, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, VK_STRUCTURE_TYPE_SUBMIT_INFO, VK_SUBOPTIMAL_KHR, VK_SUCCESS, vkAcquireNextImageKHR(), vkQueuePresentKHR(), vkQueueSubmit(), vkResetFences(), vkWaitForFences(), VkSubmitInfo::waitSemaphoreCount, VkPresentInfoKHR::waitSemaphoreCount, VkExtent2D::width, and SDLTest_CommonState::windows.

Referenced by main().

{
uint32_t frameIndex;
VkResult result;
double currentTime;
VkClearColorValue clearColor = {0};
VkPipelineStageFlags waitDestStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
VkSubmitInfo submitInfo = {0};
VkPresentInfoKHR presentInfo = {0};
int w, h;
if(!vulkanContext.swapchain)
{
SDL_bool retval = createNewSwapchainAndSwapchainSpecificStuff();
if(!retval)
SDL_Delay(100);
return retval;
}
result = vkAcquireNextImageKHR(vulkanContext.device,
vulkanContext.swapchain,
UINT64_MAX,
vulkanContext.imageAvailableSemaphore,
VK_NULL_HANDLE,
&frameIndex);
if(result == VK_ERROR_OUT_OF_DATE_KHR)
return createNewSwapchainAndSwapchainSpecificStuff();
if(result != VK_SUBOPTIMAL_KHR && result != VK_SUCCESS)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkAcquireNextImageKHR(): %s\n",
getVulkanResultString(result));
quit(2);
}
result = vkWaitForFences(
vulkanContext.device, 1, &vulkanContext.fences[frameIndex], VK_FALSE, UINT64_MAX);
if(result != VK_SUCCESS)
{
SDL_LogError(
SDL_LOG_CATEGORY_APPLICATION, "vkWaitForFences(): %s\n", getVulkanResultString(result));
quit(2);
}
result = vkResetFences(vulkanContext.device, 1, &vulkanContext.fences[frameIndex]);
if(result != VK_SUCCESS)
{
SDL_LogError(
SDL_LOG_CATEGORY_APPLICATION, "vkResetFences(): %s\n", getVulkanResultString(result));
quit(2);
}
currentTime = (double)SDL_GetPerformanceCounter() / SDL_GetPerformanceFrequency();
clearColor.float32[0] = (float)(0.5 + 0.5 * SDL_sin(currentTime));
clearColor.float32[1] = (float)(0.5 + 0.5 * SDL_sin(currentTime + M_PI * 2 / 3));
clearColor.float32[2] = (float)(0.5 + 0.5 * SDL_sin(currentTime + M_PI * 4 / 3));
clearColor.float32[3] = 1;
rerecordCommandBuffer(frameIndex, &clearColor);
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submitInfo.waitSemaphoreCount = 1;
submitInfo.pWaitSemaphores = &vulkanContext.imageAvailableSemaphore;
submitInfo.pWaitDstStageMask = &waitDestStageMask;
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &vulkanContext.commandBuffers[frameIndex];
submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = &vulkanContext.renderingFinishedSemaphore;
result = vkQueueSubmit(
vulkanContext.graphicsQueue, 1, &submitInfo, vulkanContext.fences[frameIndex]);
if(result != VK_SUCCESS)
{
SDL_LogError(
SDL_LOG_CATEGORY_APPLICATION, "vkQueueSubmit(): %s\n", getVulkanResultString(result));
quit(2);
}
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
presentInfo.waitSemaphoreCount = 1;
presentInfo.pWaitSemaphores = &vulkanContext.renderingFinishedSemaphore;
presentInfo.swapchainCount = 1;
presentInfo.pSwapchains = &vulkanContext.swapchain;
presentInfo.pImageIndices = &frameIndex;
result = vkQueuePresentKHR(vulkanContext.presentQueue, &presentInfo);
if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
{
return createNewSwapchainAndSwapchainSpecificStuff();
}
if(result != VK_SUCCESS)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkQueuePresentKHR(): %s\n",
getVulkanResultString(result));
quit(2);
}
SDL_Vulkan_GetDrawableSize(state->windows[0], &w, &h);
if(w != (int)vulkanContext.swapchainSize.width || h != (int)vulkanContext.swapchainSize.height)
{
return createNewSwapchainAndSwapchainSpecificStuff();
}
return SDL_TRUE;
}
VkPresentInfoKHR::pSwapchains
const VkSwapchainKHR * pSwapchains
Definition: vulkan.h:3574
SDL_Vulkan_GetDrawableSize
#define SDL_Vulkan_GetDrawableSize
Definition: SDL_dynapi_overrides.h:637
VkPresentInfoKHR::pWaitSemaphores
const VkSemaphore * pWaitSemaphores
Definition: vulkan.h:3572
VkSubmitInfo::pCommandBuffers
const VkCommandBuffer * pCommandBuffers
Definition: vulkan.h:1701
VkPresentInfoKHR::pImageIndices
const uint32_t * pImageIndices
Definition: vulkan.h:3575
VkPresentInfoKHR::swapchainCount
uint32_t swapchainCount
Definition: vulkan.h:3573
SDL_TRUE
Definition: SDL_stdinc.h:142
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
VkSubmitInfo::sType
VkStructureType sType
Definition: vulkan.h:1695
VulkanContext::presentQueue
VkQueue presentQueue
Definition: testvulkan.c:188
VkSubmitInfo::pWaitSemaphores
const VkSemaphore * pWaitSemaphores
Definition: vulkan.h:1698
vkQueuePresentKHR
VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo)
UINT64_MAX
#define UINT64_MAX
Definition: testvulkan.c:39
VK_STRUCTURE_TYPE_SUBMIT_INFO
Definition: vulkan.h:161
VulkanContext::swapchainSize
VkExtent2D swapchainSize
Definition: testvulkan.c:197
h
GLfloat GLfloat GLfloat GLfloat h
Definition: SDL_opengl_glext.h:1946
SDL_GetPerformanceFrequency
Uint64 SDL_GetPerformanceFrequency(void)
Get the count per second of the high resolution counter.
VkSubmitInfo::pWaitDstStageMask
const VkPipelineStageFlags * pWaitDstStageMask
Definition: vulkan.h:1699
VkSubmitInfo::waitSemaphoreCount
uint32_t waitSemaphoreCount
Definition: vulkan.h:1697
VK_NULL_HANDLE
#define VK_NULL_HANDLE
Definition: vulkan.h:49
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkResult
VkResult
Definition: vulkan.h:122
SDLTest_CommonState::windows
SDL_Window ** windows
Definition: SDL_test_common.h:78
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
state
static SDLTest_CommonState * state
Definition: testvulkan.c:205
VK_PIPELINE_STAGE_TRANSFER_BIT
Definition: vulkan.h:1120
retval
SDL_bool retval
Definition: testgamecontroller.c:65
VulkanContext::commandBuffers
VkCommandBuffer * commandBuffers
Definition: testvulkan.c:201
vkQueueSubmit
VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, VkFence fence)
VkClearColorValue::float32
float float32[4]
Definition: vulkan.h:2376
VulkanContext::fences
VkFence * fences
Definition: testvulkan.c:202
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
VkClearColorValue
Definition: vulkan.h:2375
VulkanContext::renderingFinishedSemaphore
VkSemaphore renderingFinishedSemaphore
Definition: testvulkan.c:190
VkPresentInfoKHR::sType
VkStructureType sType
Definition: vulkan.h:3569
VkSubmitInfo::signalSemaphoreCount
uint32_t signalSemaphoreCount
Definition: vulkan.h:1702
VulkanContext::swapchain
VkSwapchainKHR swapchain
Definition: testvulkan.c:181
VkExtent2D::width
uint32_t width
Definition: vulkan.h:1995
w
GLubyte GLubyte GLubyte GLubyte w
Definition: SDL_opengl_glext.h:731
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_STRUCTURE_TYPE_PRESENT_INFO_KHR
Definition: vulkan.h:207
VK_SUCCESS
Definition: vulkan.h:123
rerecordCommandBuffer
static void rerecordCommandBuffer(uint32_t frameIndex, const VkClearColorValue *clearColor)
Definition: testvulkan.c:912
VkSubmitInfo
Definition: vulkan.h:1694
quit
static void quit(int rc)
Definition: testvulkan.c:211
VulkanContext::imageAvailableSemaphore
VkSemaphore imageAvailableSemaphore
Definition: testvulkan.c:189
SDL_GetPerformanceCounter
#define SDL_GetPerformanceCounter
Definition: SDL_dynapi_overrides.h:484
SDL_Delay
#define SDL_Delay
Definition: SDL_dynapi_overrides.h:486
VkSubmitInfo::commandBufferCount
uint32_t commandBufferCount
Definition: vulkan.h:1700
VK_ERROR_OUT_OF_DATE_KHR
Definition: vulkan.h:144
VkPresentInfoKHR
Definition: vulkan.h:3568
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:139
uint32_t
unsigned int uint32_t
Definition: SDL_config_windows.h:63
VulkanContext::graphicsQueue
VkQueue graphicsQueue
Definition: testvulkan.c:187
VK_SUBOPTIMAL_KHR
Definition: vulkan.h:143
vkAcquireNextImageKHR
VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex)
vkResetFences
VKAPI_ATTR VkResult VKAPI_CALL vkResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences)
VK_FALSE
#define VK_FALSE
Definition: vulkan.h:103
VkSubmitInfo::pSignalSemaphores
const VkSemaphore * pSignalSemaphores
Definition: vulkan.h:1703
VkPresentInfoKHR::waitSemaphoreCount
uint32_t waitSemaphoreCount
Definition: vulkan.h:3571
createNewSwapchainAndSwapchainSpecificStuff
static SDL_bool createNewSwapchainAndSwapchainSpecificStuff(void)
Definition: testvulkan.c:975
vkWaitForFences
VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences, VkBool32 waitAll, uint64_t timeout)
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
VkExtent2D::height
uint32_t height
Definition: vulkan.h:1996
SDL_sin
#define SDL_sin
Definition: SDL_dynapi_overrides.h:435
VkPipelineStageFlags
VkFlags VkPipelineStageFlags
Definition: vulkan.h:1128

## rerecordCommandBuffer()

static void rerecordCommandBuffer | ( | uint32_t | frameIndex,
|  | const VkClearColorValue * | clearColor
| ) |  |

static

Definition at line 912 of file testvulkan.c.

References VkImageSubresourceRange::aspectMask, VkImageSubresourceRange::baseArrayLayer, VkImageSubresourceRange::baseMipLevel, VulkanContext::commandBuffers, VkCommandBufferBeginInfo::flags, getVulkanResultString(), VkImageSubresourceRange::layerCount, VkImageSubresourceRange::levelCount, quit(), recordPipelineImageBarrier(), SDL_LOG_CATEGORY_APPLICATION, SDL_LogError, VkCommandBufferBeginInfo::sType, VulkanContext::swapchainImages, VK_ACCESS_MEMORY_READ_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_UNDEFINED, VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, VK_SUCCESS, vkBeginCommandBuffer(), vkCmdClearColorImage(), vkEndCommandBuffer(), and vkResetCommandBuffer().

Referenced by render().

{
VkCommandBuffer commandBuffer = vulkanContext.commandBuffers[frameIndex];
VkImage image = vulkanContext.swapchainImages[frameIndex];
VkCommandBufferBeginInfo beginInfo = {0};
VkImageSubresourceRange clearRange = {0};
VkResult result = vkResetCommandBuffer(commandBuffer, 0);
if(result != VK_SUCCESS)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkResetCommandBuffer(): %s\n",
getVulkanResultString(result));
quit(2);
}
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
result = vkBeginCommandBuffer(commandBuffer, &beginInfo);
if(result != VK_SUCCESS)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkBeginCommandBuffer(): %s\n",
getVulkanResultString(result));
quit(2);
}
recordPipelineImageBarrier(commandBuffer,
0,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
image);
clearRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
clearRange.baseMipLevel = 0;
clearRange.levelCount = 1;
clearRange.baseArrayLayer = 0;
clearRange.layerCount = 1;
vkCmdClearColorImage(
commandBuffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, clearColor, 1, &clearRange);
recordPipelineImageBarrier(commandBuffer,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_MEMORY_READ_BIT,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
image);
result = vkEndCommandBuffer(commandBuffer);
if(result != VK_SUCCESS)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"vkEndCommandBuffer(): %s\n",
getVulkanResultString(result));
quit(2);
}
}
vkBeginCommandBuffer
VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo)
recordPipelineImageBarrier
static void recordPipelineImageBarrier(VkCommandBuffer commandBuffer, VkAccessFlags sourceAccessMask, VkAccessFlags destAccessMask, VkImageLayout sourceLayout, VkImageLayout destLayout, VkImage image)
Definition: testvulkan.c:879
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
image
GLeglImageOES image
Definition: SDL_opengl.h:2148
VK_IMAGE_LAYOUT_UNDEFINED
Definition: vulkan.h:613
VK_ACCESS_TRANSFER_WRITE_BIT
Definition: vulkan.h:1308
VkImageSubresourceRange::baseMipLevel
uint32_t baseMipLevel
Definition: vulkan.h:1886
vkEndCommandBuffer
VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
getVulkanResultString
static const char * getVulkanResultString(VkResult result)
Definition: testvulkan.c:111
VkResult
VkResult
Definition: vulkan.h:122
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO
Definition: vulkan.h:199
VK_IMAGE_ASPECT_COLOR_BIT
Definition: vulkan.h:1132
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
Definition: vulkan.h:622
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
VkImageSubresourceRange
Definition: vulkan.h:1884
VulkanContext::commandBuffers
VkCommandBuffer * commandBuffers
Definition: testvulkan.c:201
VkCommandBufferBeginInfo::sType
VkStructureType sType
Definition: vulkan.h:2332
VkCommandBufferBeginInfo::flags
VkCommandBufferUsageFlags flags
Definition: vulkan.h:2334
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VK_SUCCESS
Definition: vulkan.h:123
quit
static void quit(int rc)
Definition: testvulkan.c:211
VkImageSubresourceRange::aspectMask
VkImageAspectFlags aspectMask
Definition: vulkan.h:1885
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
Definition: vulkan.h:620
VkImageSubresourceRange::baseArrayLayer
uint32_t baseArrayLayer
Definition: vulkan.h:1888
vkCmdClearColorImage
VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearColorValue *pColor, uint32_t rangeCount, const VkImageSubresourceRange *pRanges)
VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
Definition: vulkan.h:1344
VK_ACCESS_MEMORY_READ_BIT
Definition: vulkan.h:1311
VkImageSubresourceRange::levelCount
uint32_t levelCount
Definition: vulkan.h:1887
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
vkResetCommandBuffer
VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags)
VkCommandBufferBeginInfo
Definition: vulkan.h:2331
VkImageSubresourceRange::layerCount
uint32_t layerCount
Definition: vulkan.h:1889
VulkanContext::swapchainImages
VkImage * swapchainImages
Definition: testvulkan.c:200

## shutdownVulkan()

static void shutdownVulkan | ( | void |  | ) |

static

Definition at line 1004 of file testvulkan.c.

References destroySwapchainAndSwapchainSpecificStuff(), VulkanContext::device, VulkanContext::imageAvailableSemaphore, VulkanContext::instance, NULL, VulkanContext::renderingFinishedSemaphore, SDL_free, SDL_TRUE, SDL_Vulkan_UnloadLibrary, VulkanContext::surface, VulkanContext::surfaceFormats, vkDestroyDevice(), vkDestroyInstance(), vkDestroySemaphore(), vkDestroySurfaceKHR(), and vkDeviceWaitIdle().

Referenced by quit().

{
if(vulkanContext.device && vkDeviceWaitIdle)
vkDeviceWaitIdle(vulkanContext.device);
destroySwapchainAndSwapchainSpecificStuff(SDL_TRUE);
if(vulkanContext.imageAvailableSemaphore && vkDestroySemaphore)
vkDestroySemaphore(vulkanContext.device, vulkanContext.imageAvailableSemaphore, NULL);
if(vulkanContext.renderingFinishedSemaphore && vkDestroySemaphore)
vkDestroySemaphore(vulkanContext.device, vulkanContext.renderingFinishedSemaphore, NULL);
if(vulkanContext.device && vkDestroyDevice)
vkDestroyDevice(vulkanContext.device, NULL);
if(vulkanContext.surface && vkDestroySurfaceKHR)
vkDestroySurfaceKHR(vulkanContext.instance, vulkanContext.surface, NULL);
if(vulkanContext.instance && vkDestroyInstance)
vkDestroyInstance(vulkanContext.instance, NULL);
SDL_free(vulkanContext.surfaceFormats);
SDL_Vulkan_UnloadLibrary();
}
VulkanContext::surface
VkSurfaceKHR surface
Definition: testvulkan.c:180
SDL_TRUE
Definition: SDL_stdinc.h:142
vkDestroyDevice
VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator)
vkDestroySurfaceKHR
VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks *pAllocator)
VulkanContext::surfaceFormats
VkSurfaceFormatKHR * surfaceFormats
Definition: testvulkan.c:192
VulkanContext::instance
VkInstance instance
Definition: testvulkan.c:178
VulkanContext::device
VkDevice device
Definition: testvulkan.c:179
VulkanContext::renderingFinishedSemaphore
VkSemaphore renderingFinishedSemaphore
Definition: testvulkan.c:190
vkDeviceWaitIdle
VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(VkDevice device)
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
vkDestroySemaphore
VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks *pAllocator)
vulkanContext
static VulkanContext vulkanContext
Definition: testvulkan.c:206
VulkanContext::imageAvailableSemaphore
VkSemaphore imageAvailableSemaphore
Definition: testvulkan.c:189
NULL
#define NULL
Definition: begin_code.h:164
SDL_Vulkan_UnloadLibrary
#define SDL_Vulkan_UnloadLibrary
Definition: SDL_dynapi_overrides.h:634
vkDestroyInstance
VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator)
destroySwapchainAndSwapchainSpecificStuff
static void destroySwapchainAndSwapchainSpecificStuff(SDL_bool doDestroySwapchain)
Definition: testvulkan.c:966

## Variable Documentation

## state

SDLTest_CommonState* state

static

Definition at line 205 of file testvulkan.c.

## vkGetInstanceProcAddr

PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL

static

Definition at line 94 of file testvulkan.c.

## vulkanContext

VulkanContext vulkanContext = {0}

static

Definition at line 206 of file testvulkan.c.