Mercurial > games > semicongine
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 95:8011e4d6372d | 96:b9fc90de1450 |
|---|---|
| 1 import std/tables | |
| 2 import std/options | |
| 3 | |
| 1 import semicongine/vulkan | 4 import semicongine/vulkan |
| 2 import semicongine/platform/window | 5 import semicongine/platform/window |
| 3 | 6 |
| 4 | 7 |
| 5 when isMainModule: | 8 when isMainModule: |
| 10 echo "Instance extensions" | 13 echo "Instance extensions" |
| 11 for extension in getInstanceExtensions(): | 14 for extension in getInstanceExtensions(): |
| 12 echo " " & extension | 15 echo " " & extension |
| 13 | 16 |
| 14 # create instance | 17 # create instance |
| 15 var instance = createInstance( | 18 var thewindow = createWindow("Test") |
| 19 var instance = thewindow.createInstance( | |
| 16 vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0), | 20 vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0), |
| 17 instanceExtensions= @["VK_EXT_debug_utils"], | 21 instanceExtensions= @["VK_EXT_debug_utils"], |
| 18 layers= @["VK_LAYER_KHRONOS_validation"] | 22 layers= @["VK_LAYER_KHRONOS_validation"] |
| 19 ) | 23 ) |
| 20 var debugger = instance.createDebugMessenger() | 24 var debugger = instance.createDebugMessenger() |
| 21 | 25 |
| 22 # create surface | |
| 23 var thewindow = createWindow("Test") | |
| 24 var surface = instance.createSurface(thewindow) | |
| 25 | |
| 26 # diagnostic output | 26 # diagnostic output |
| 27 echo "Devices" | 27 echo "Devices" |
| 28 for device in instance.getPhysicalDevices(): | 28 for device in instance.getPhysicalDevices(): |
| 29 echo " " & $device | 29 echo " " & $device |
| 30 echo " Rating: " & $device.rateGraphics() | |
| 30 echo " Extensions" | 31 echo " Extensions" |
| 31 for extension in device.getExtensions(): | 32 for extension in device.getExtensions(): |
| 32 echo " " & $extension | 33 echo " " & $extension |
| 34 echo " Properties" | |
| 35 echo " " & $device.getProperties() | |
| 36 echo " Features" | |
| 37 echo " " & $device.getFeatures() | |
| 33 echo " Queue families" | 38 echo " Queue families" |
| 34 for queueFamily in device.getQueueFamilies(): | 39 for queueFamily in device.getQueueFamilies(): |
| 35 echo " " & $queueFamily | 40 echo " " & $queueFamily |
| 36 echo " Surface present modes" | 41 echo " Surface present modes" |
| 37 for mode in device.getSurfacePresentModes(surface): | 42 for mode in device.getSurfacePresentModes(): |
| 38 echo " " & $mode | 43 echo " " & $mode |
| 39 echo " Surface formats" | 44 echo " Surface formats" |
| 40 for format in device.getSurfaceFormats(surface): | 45 for format in device.getSurfaceFormats(): |
| 41 echo " " & $format | 46 echo " " & $format |
| 42 | 47 |
| 43 # create devices | 48 # create devices |
| 44 var devices: seq[Device] | 49 let selectedPhysicalDevice = instance.getPhysicalDevices().filterBestGraphics() |
| 45 for physicalDevice in instance.getPhysicalDevices(): | 50 var device = instance.createDevice( |
| 46 devices.add physicalDevice.createDevice([], [], physicalDevice.getQueueFamilies(surface).filterForGraphicsPresentationQueues()) | 51 selectedPhysicalDevice, |
| 52 @[], | |
| 53 @[], | |
| 54 selectedPhysicalDevice.filterForGraphicsPresentationQueues() | |
| 55 ) | |
| 56 | |
| 57 echo "Created device ", device.physicalDevice.name | |
| 58 var (swapchain, res) = device.createSwapchain(device.physicalDevice.getSurfaceFormats().filterSurfaceFormat()) | |
| 59 if res != VK_SUCCESS: | |
| 60 raise newException(Exception, "Unable to create swapchain") | |
| 61 | |
| 62 echo "All successfull" | |
| 63 echo "Start cleanup" | |
| 47 | 64 |
| 48 # cleanup | 65 # cleanup |
| 49 surface.destroy() | 66 swapchain.destroy() |
| 50 for device in devices.mitems: | 67 device.destroy() |
| 51 device.destroy() | |
| 52 | 68 |
| 53 debugger.destroy() | 69 debugger.destroy() |
| 54 instance.destroy() | 70 instance.destroy() |
