From bb5f062751c3492e4916675326ca780f2bf3d4b2 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Thu, 23 Dec 2021 11:03:38 +0200 Subject: [PATCH] init flags mechanism --- src/app.c | 10 +++++++++- src/vk.c | 30 +++++++++++++++++++++++++++--- src/vk.h | 8 +++++++- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/app.c b/src/app.c index 1d97906..0dca609 100644 --- a/src/app.c +++ b/src/app.c @@ -1,12 +1,20 @@ +#include #include #include "app.h" #include "vk.h" int app_init(void) { - if(vk_init() == -1) { + unsigned int flags; + + if(vk_init(VKINIT_DEPTH | VKINIT_RAY, &flags) == -1) { return -1; } + if(!(flags & VKINIT_RAY)) { + fprintf(stderr, "Vulkan raytracing extensions not available\n"); + /*vk_cleanup(); + return -1;*/ + } return 0; } diff --git a/src/vk.c b/src/vk.c index f3cb508..917a801 100644 --- a/src/vk.c +++ b/src/vk.c @@ -26,6 +26,7 @@ static int have_ext(VkExtensionProperties *ext, int next, const char *name); static Display *dpy; static Window win; +static int initflags; static VkInstance vk; static VkPhysicalDevice vkpdev; @@ -57,12 +58,22 @@ void vk_init_xwin(Display *d, Window w) win = w; } -int vk_init(void) +int vk_init(unsigned int flags, unsigned int *usedflags) { + initflags = flags; if(create_instance() == -1) return -1; if(create_surface() == -1) return -1; if(choose_phys_dev() == -1) return -1; if(create_device() == -1) return -1; + + if(initflags != flags) { + if(usedflags) { + *usedflags = initflags; + } else { + vk_cleanup(); + return -1; + } + } return 0; } @@ -124,7 +135,10 @@ int vk_reshape(int xsz, int ysz) vksc_extent.width = xsz; vksc_extent.height = ysz; - return create_swapchain(); + if(create_swapchain() == -1) return -1; + + /* TODO create depth/stencil buffers as needed (initflags) */ + return 0; } #define ARRSZ(arr) (sizeof arr / sizeof *arr) @@ -316,7 +330,7 @@ static int create_device(void) VkDeviceQueueCreateInfo qinf = {0}; VkPhysicalDeviceFeatures feat = {0}; VkDeviceCreateInfo devinf = {0}; - const char *ext[ARRSZ(known_devext_list)]; + const char *ext[ARRSZ(known_devext_list) + 16]; int i, num_ext; vkEnumerateDeviceExtensionProperties(vkpdev, 0, &dev_ext_count, 0); @@ -334,6 +348,16 @@ static int create_device(void) } } + if(initflags & VKINIT_RAY) { + if(have_ext(dev_ext, dev_ext_count, "VK_KHR_acceleration_structure") && + have_ext(dev_ext, dev_ext_count, "VK_KHR_ray_tracing_pipeline")) { + ext[num_ext++] = "VK_KHR_acceleration_structure"; + ext[num_ext++] = "VK_KHR_ray_tracing_pipeline"; + } else { + initflags &= ~VKINIT_RAY; + } + } + qinf.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; qinf.queueFamilyIndex = vkqfam_idx; qinf.queueCount = 1; diff --git a/src/vk.h b/src/vk.h index 746b0e0..39e2df9 100644 --- a/src/vk.h +++ b/src/vk.h @@ -3,9 +3,15 @@ #include +enum { + VKINIT_DEPTH = 1, + VKINIT_STENCIL = 2, + VKINIT_RAY = 0x100 +}; + void vk_init_xwin(Display *dpy, Window win); -int vk_init(void); +int vk_init(unsigned int flags, unsigned int *usedflags); void vk_cleanup(void); int vk_reshape(int xsz, int ysz); -- 1.7.10.4