Cleanup + assertions + debugging

master
itycodes 3 weeks ago
parent 220eff9b3d
commit b058a2c5b0

@ -3,7 +3,7 @@
SHADERS = vert.spv frag.spv SHADERS = vert.spv frag.spv
CC = gcc CC = gcc
LIBS = -lvulkan -lglfw -lm LIBS = -lvulkan -lglfw -lm
CFLAGS = $(LIBS) CFLAGS = $(LIBS) -g
OUT = main OUT = main
SRC = main.c SRC = main.c

@ -17,6 +17,12 @@
#define MESH_SIZE 36*2*4*4 #define MESH_SIZE 36*2*4*4
#define ASSERT(cond, msg)\
if(!(cond)) {\
fprintf(stderr, "Runtime assertion %s at %s:%d failed: %s\n", #cond, __FILE__, __LINE__, msg);\
exit(-1);\
}
float pos_y = 0.0; float pos_y = 0.0;
float pos_z = 0.0; float pos_z = 0.0;
float pos_x = 0.0; float pos_x = 0.0;
@ -65,7 +71,7 @@ void key_callback(GLFWwindow* win, int key, int scancode, int action, int mods)
} }
int main() { int main() {
//glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11); glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
uint32_t glfw_res = glfwInit(); uint32_t glfw_res = glfwInit();
printf("glfwInit: (%d)\n", glfw_res); printf("glfwInit: (%d)\n", glfw_res);
//glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); //glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
@ -109,7 +115,8 @@ int main() {
VkSurfaceKHR surface; VkSurfaceKHR surface;
{ {
res = glfwCreateWindowSurface(vkins, win, NULL, &surface); res = glfwCreateWindowSurface(vkins, win, NULL, &surface);
printf("CreateWindowSurface: (%ld)\n", res); printf("CreateWindowSurface: (%018p) (%018p, %018p)\n", res, VK_ERROR_EXTENSION_NOT_PRESENT, VK_ERROR_NATIVE_WINDOW_IN_USE_KHR);
ASSERT(surface != NULL, "Failed to create GLFW Window Surface.");
} }
VkPhysicalDevice pdev; VkPhysicalDevice pdev;
@ -121,6 +128,8 @@ int main() {
VkPhysicalDevice* phys_devs = malloc(sizeof(VkPhysicalDevice) * num_d); VkPhysicalDevice* phys_devs = malloc(sizeof(VkPhysicalDevice) * num_d);
res = vkEnumeratePhysicalDevices(vkins, &num_d, &phys_devs[0]); res = vkEnumeratePhysicalDevices(vkins, &num_d, &phys_devs[0]);
printf("EnumeratePhysicalDevices 2: (%ld) %lu\n", res, num_d); printf("EnumeratePhysicalDevices 2: (%ld) %lu\n", res, num_d);
ASSERT(num_d > 0, "Failed to detect any physical devices.");
ASSERT(res == VK_SUCCESS, "Failed to enumerate physical devices.");
pdev = phys_devs[0]; pdev = phys_devs[0];
} }
@ -828,7 +837,7 @@ int main() {
VkSwapchainKHR swapchain; VkSwapchainKHR swapchain;
{ {
VkSurfaceCapabilitiesKHR caps; VkSurfaceCapabilitiesKHR caps = {};
res = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(pdev, surface, &caps); res = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(pdev, surface, &caps);
printf("GetPhysicalDeviceSurfaceCapabilitiesKHR: (%ld)\n", res); printf("GetPhysicalDeviceSurfaceCapabilitiesKHR: (%ld)\n", res);
printf("minImageCount: %d\n", caps.minImageCount); printf("minImageCount: %d\n", caps.minImageCount);
@ -1135,6 +1144,7 @@ int main() {
unsigned long long time_now = get_time(); unsigned long long time_now = get_time();
printf(" \r"); printf(" \r");
fflush(stdout); fflush(stdout);
usleep(12);
printf("ms per frame: %llu\r", (time_now - time_bef)/1000); printf("ms per frame: %llu\r", (time_now - time_bef)/1000);
fflush(stdout); fflush(stdout);
} }

Loading…
Cancel
Save