#include "util.h"
#include "darray.h"
-#ifdef __WIN32__
+#ifdef _WIN32
+#include <windows.h>
#include <vulkan/vulkan_win32.h>
#else
/*#include <vulkan/vulkan_xlib.h>*/
static int have_inst_layer(const char *name);
static int have_ext(VkExtensionProperties *ext, int next, const char *name);
+#ifdef _WIN32
+static HINSTANCE hinst;
+static HWND win;
+#else
static Display *dpy;
static Window win;
+#endif
static int initflags;
#define MAX_INIT_QUEUE 32
static struct {
static int have_raytrace, have_debug_report;
+#ifdef _WIN32
+void vk_init_win(HINSTANCE hi, HWND w)
+{
+ hinst = hi;
+ win = w;
+}
+#else
void vk_init_xwin(Display *d, Window w)
{
dpy = d;
win = w;
}
+#endif
void vk_init_queue(unsigned int qflags, int count)
{
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;
- }
+ if(initflags != flags && !usedflags) {
+ vk_cleanup();
+ return -1;
+ }
+
+ if(usedflags) {
+ *usedflags = initflags;
}
return 0;
}
int required;
} known_instext_list[] = {
{"VK_KHR_surface", 1},
-#ifdef __WIN32__
+#ifdef _WIN32
{"VK_KHR_win32_surface", 1},
#else
/*{"VK_KHR_xlib_surface", 1},*/
} known_devext_list[] = {
{"VK_KHR_swapchain", 1},
{"VK_KHR_acceleration_structure", 0},
+ {"VK_KHR_deferred_host_operations", 0},
{"VK_KHR_ray_tracing_pipeline", 0}
};
static int create_surface(void)
{
+#ifdef _WIN32
+ VkWin32SurfaceCreateInfoKHR winf = {0};
+ winf.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
+ winf.hinstance = hinst;
+ winf.hwnd = win;
+
+ if(vkCreateWin32SurfaceKHR(vk, &winf, 0, &vksurf) != 0) {
+ fprintf(stderr, "failed to create win32 window surface\n");
+ return -1;
+ }
+#else
/*
VkXlibSurfaceCreateInfoKHR xinf = {0};
xinf.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
fprintf(stderr, "failed to create XCB window surface\n");
return -1;
}
+#endif
return 0;
}
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_deferred_host_operations") &&
have_ext(dev_ext, dev_ext_count, "VK_KHR_ray_tracing_pipeline")) {
ext[num_ext++] = "VK_KHR_acceleration_structure";
+ ext[num_ext++] = "VK_KHR_deferred_host_operations";
ext[num_ext++] = "VK_KHR_ray_tracing_pipeline";
} else {
initflags &= ~VKINIT_RAY;
return -1;
}
- if(!vksc_img || vksc_numimg != num) {
+ if(!vksc_img) {
free(vksc_img);
vkGetSwapchainImagesKHR(vkdev, vksc, &num, 0);
vksc_img = malloc_nf(num * sizeof *vksc_img);