diff src/vulkan_helpers.nim @ 10:0660ba9d1930

did: make it work on windows
author sam <sam@basx.dev>
date Sat, 24 Dec 2022 22:32:46 +0700
parents 4ed9cb098315
children 9e5fe647ff91
line wrap: on
line diff
--- a/src/vulkan_helpers.nim	Thu Dec 22 19:35:54 2022 +0700
+++ b/src/vulkan_helpers.nim	Sat Dec 24 22:32:46 2022 +0700
@@ -2,24 +2,24 @@
 import std/strutils
 import std/strformat
 import std/logging
+import std/macros
 
 import ./glslang/glslang
 import ./vulkan
 import ./window
 
-when defined(release):
-  const ENABLEVULKANVALIDATIONLAYERS* = false
-else:
-  const ENABLEVULKANVALIDATIONLAYERS* = true
+
+const ENABLEVULKANVALIDATIONLAYERS* = not defined(release)
 
 
 template checkVkResult*(call: untyped) =
   when defined(release):
     discard call
   else:
-    debug(&"CALLING vulkan: {astToStr(call)}")
+    debug "CALLING vulkan: ", astToStr(call)
     let value = call
     if value != VK_SUCCESS:
+      error "Vulkan error: ",  astToStr(call),  " returned ", $value
       raise newException(Exception, "Vulkan error: " & astToStr(call) & " returned " & $value)
 
 func addrOrNil[T](obj: var openArray[T]): ptr T =
@@ -128,17 +128,27 @@
 
 
 proc createVulkanInstance*(vulkanVersion: uint32): VkInstance =
-  var requiredExtensions = [
-    "VK_EXT_acquire_xlib_display".cstring,
-    "VK_EXT_direct_mode_display".cstring,
-    "VK_KHR_display".cstring,
-    "VK_KHR_surface".cstring,
-    "VK_KHR_xlib_surface".cstring,
-    "VK_EXT_debug_utils".cstring,
-  ]
+
+  when defined(linux):
+    var requiredExtensions = [
+      # "VK_EXT_acquire_xlib_display".cstring,
+      # "VK_EXT_direct_mode_display".cstring,
+      # "VK_KHR_display".cstring,
+      "VK_KHR_surface".cstring,
+      "VK_KHR_xlib_surface".cstring,
+      "VK_EXT_debug_utils".cstring,
+    ]
+  when defined(windows):
+    var requiredExtensions = [
+      "VK_KHR_win32_surface".cstring,
+      #"VK_KHR_display".cstring,
+      "VK_KHR_surface".cstring,
+      "VK_EXT_debug_utils".cstring,
+    ]
+  
   let availableExtensions = getInstanceExtensions()
   for extension in requiredExtensions:
-    assert $extension in availableExtensions
+    assert $extension in availableExtensions, $extension
 
   let desiredLayers = ["VK_LAYER_KHRONOS_validation".cstring, "VK_LAYER_MESA_overlay".cstring]
   let availableLayers = getValidationLayers()
@@ -171,7 +181,10 @@
   checkVkResult vkCreateInstance(addr(createinfo), nil, addr(result))
 
   loadVK_KHR_surface()
-  loadVK_KHR_xlib_surface()
+  when defined(linux):
+    loadVK_KHR_xlib_surface()
+  when defined(windows):
+    loadVK_KHR_win32_surface()
   loadVK_KHR_swapchain()
   when ENABLEVULKANVALIDATIONLAYERS:
     loadVK_EXT_debug_utils(result)