diff tests/test_vulkan_wrapper.nim @ 96:b9fc90de1450

add: swapchain API, more refactoring
author Sam <sam@basx.dev>
date Wed, 01 Mar 2023 23:58:39 +0700
parents f036546f5ea2
children 110ed3ee5df8
line wrap: on
line diff
--- a/tests/test_vulkan_wrapper.nim	Wed Mar 01 00:01:06 2023 +0700
+++ b/tests/test_vulkan_wrapper.nim	Wed Mar 01 23:58:39 2023 +0700
@@ -1,3 +1,6 @@
+import std/tables
+import std/options
+
 import semicongine/vulkan
 import semicongine/platform/window
 
@@ -12,43 +15,56 @@
     echo "  " & extension
 
   # create instance
-  var instance = createInstance(
+  var thewindow = createWindow("Test")
+  var instance = thewindow.createInstance(
     vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0),
     instanceExtensions= @["VK_EXT_debug_utils"],
     layers= @["VK_LAYER_KHRONOS_validation"]
   )
   var debugger = instance.createDebugMessenger()
 
-  # create surface
-  var thewindow = createWindow("Test")
-  var surface = instance.createSurface(thewindow)
-
   # diagnostic output
   echo "Devices"
   for device in instance.getPhysicalDevices():
     echo "  " & $device
+    echo "  Rating: " & $device.rateGraphics()
     echo "  Extensions"
     for extension in device.getExtensions():
       echo "    " & $extension
+    echo "  Properties"
+    echo "  " & $device.getProperties()
+    echo "  Features"
+    echo "  " & $device.getFeatures()
     echo "  Queue families"
     for queueFamily in device.getQueueFamilies():
       echo "    " & $queueFamily
     echo "  Surface present modes"
-    for mode in device.getSurfacePresentModes(surface):
+    for mode in device.getSurfacePresentModes():
       echo "    " & $mode
     echo "  Surface formats"
-    for format in device.getSurfaceFormats(surface):
+    for format in device.getSurfaceFormats():
       echo "    " & $format
 
   # create devices
-  var devices: seq[Device]
-  for physicalDevice in instance.getPhysicalDevices():
-    devices.add physicalDevice.createDevice([], [], physicalDevice.getQueueFamilies(surface).filterForGraphicsPresentationQueues())
+  let selectedPhysicalDevice = instance.getPhysicalDevices().filterBestGraphics()
+  var device = instance.createDevice(
+    selectedPhysicalDevice,
+    @[],
+    @[],
+    selectedPhysicalDevice.filterForGraphicsPresentationQueues()
+  )
+
+  echo "Created device ", device.physicalDevice.name
+  var (swapchain, res) = device.createSwapchain(device.physicalDevice.getSurfaceFormats().filterSurfaceFormat())
+  if res != VK_SUCCESS:
+    raise newException(Exception, "Unable to create swapchain")
+
+  echo "All successfull"
+  echo "Start cleanup"
 
   # cleanup
-  surface.destroy()
-  for device in devices.mitems:
-    device.destroy()
+  swapchain.destroy()
+  device.destroy()
 
   debugger.destroy()
   instance.destroy()