summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/main.c b/main.c
index 720850a..273f51f 100644
--- a/main.c
+++ b/main.c
@@ -6,6 +6,7 @@
#include <string.h>
static SDL_Window *window = NULL;
+static VkDebugUtilsMessengerEXT debug_messenger;
static VkInstance instance = VK_NULL_HANDLE;
static VkPhysicalDevice phy_gpu = VK_NULL_HANDLE;
static VkDevice gpu = VK_NULL_HANDLE;
@@ -148,6 +149,12 @@ void cleanup() {
SDL_DestroyWindow(window);
}
+static VKAPI_ATTR VkBool32 VKAPI_CALL debug_callback( VkDebugUtilsMessageSeverityFlagBitsEXT severity,
+ VkDebugUtilsMessageTypeFlagsEXT type, const VkDebugUtilsMessengerCallbackDataEXT *callback_data, void *data) {
+ fprintf(stderr, "validation layer: %s\n", callback_data->pMessage);
+ return VK_FALSE;
+}
+
void create_instance() {
VkApplicationInfo app_info = {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
@@ -161,17 +168,22 @@ void create_instance() {
uint32_t sdl_exts = 0;
SDL_Vulkan_GetInstanceExtensions(window, &sdl_exts, NULL);
- const char *sdl_exts_names[sdl_exts];
+ const char *sdl_exts_names[sdl_exts + 1];
SDL_Vulkan_GetInstanceExtensions(window, &sdl_exts, sdl_exts_names);
+ sdl_exts_names[sdl_exts++] = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
+
for (size_t i = 0; i < sdl_exts; i++) {
puts(sdl_exts_names[i]);
};
+ const char *validation_layers[] = { "VK_LAYER_KHRONOS_validation" };
+
VkInstanceCreateInfo create_info = {
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pApplicationInfo = &app_info,
- .enabledLayerCount = 0,
+ .enabledLayerCount = 1,
+ .ppEnabledLayerNames = validation_layers,
.enabledExtensionCount = sdl_exts,
.ppEnabledExtensionNames = sdl_exts_names,
};
@@ -181,6 +193,20 @@ void create_instance() {
fputs("failed to create vk instance", stderr);
exit(-1);
}
+
+ VkDebugUtilsMessengerCreateInfoEXT debug_create_info = {
+ .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
+ .messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT
+ | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT
+ | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT,
+ .messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT
+ | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT
+ | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT,
+ .pfnUserCallback = debug_callback
+ };
+
+ ((PFN_vkCreateDebugUtilsMessengerEXT)
+ vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT"))(instance, &debug_create_info, NULL, &debug_messenger);
}
struct queue_indices find_queue_families(VkPhysicalDevice dev) {
@@ -802,7 +828,9 @@ void draw() {
.pWaitSemaphores = wait_semaphores,
.pWaitDstStageMask = wait_stages,
.signalSemaphoreCount = 1,
- .pSignalSemaphores = signal_semaphores
+ .pSignalSemaphores = signal_semaphores,
+ .commandBufferCount = 1,
+ .pCommandBuffers = &command_buffer
};
VkResult res = vkQueueSubmit(gfx_queue, 1, &submit_info, in_flight_fence);