annotate src/semicongine/vulkan/physicaldevice.nim @ 96:b9fc90de1450

add: swapchain API, more refactoring
author Sam <sam@basx.dev>
date Wed, 01 Mar 2023 23:58:39 +0700
parents
children 110ed3ee5df8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
1 import std/enumerate
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
2 import std/options
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
3 import std/tables
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
4 import std/sequtils
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
5
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
6 import ./api
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
7 import ./utils
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
8 import ./instance
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
9
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
10 type
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
11 PhysicalDevice* = object
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
12 vk*: VkPhysicalDevice
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
13 name*: string
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
14 devicetype*: VkPhysicalDeviceType
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
15 surface*: VkSurfaceKHR
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
16 QueueFamily* = object
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
17 device: PhysicalDevice
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
18 properties*: VkQueueFamilyProperties
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
19 index*: uint32
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
20 flags*: seq[VkQueueFlagBits]
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
21
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
22 proc getProperties*(device: PhysicalDevice): VkPhysicalDeviceProperties =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
23 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
24 device.vk.vkGetPhysicalDeviceProperties(addr result)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
25
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
26 proc getPhysicalDevices*(instance: Instance): seq[PhysicalDevice] =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
27 assert instance.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
28 assert instance.surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
29 var nDevices: uint32
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
30 checkVkResult vkEnumeratePhysicalDevices(instance.vk, addr(nDevices), nil)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
31 var devices = newSeq[VkPhysicalDevice](nDevices)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
32 checkVkResult vkEnumeratePhysicalDevices(instance.vk, addr(nDevices), devices.toCPointer)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
33 for i in 0 ..< nDevices:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
34 var device = PhysicalDevice(vk: devices[i], surface: instance.surface)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
35 let props = device.getProperties()
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
36 device.name = props.deviceName.cleanString()
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
37 device.devicetype = props.deviceType
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
38 result.add device
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
39
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
40 proc getExtensions*(device: PhysicalDevice): seq[string] =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
41 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
42 var extensionCount: uint32
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
43 checkVkResult vkEnumerateDeviceExtensionProperties(device.vk, nil, addr(extensionCount), nil)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
44 if extensionCount > 0:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
45 var extensions = newSeq[VkExtensionProperties](extensionCount)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
46 checkVkResult vkEnumerateDeviceExtensionProperties(device.vk, nil, addr(extensionCount), extensions.toCPointer)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
47 for extension in extensions:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
48 result.add(cleanString(extension.extensionName))
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
49
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
50 proc getFeatures*(device: PhysicalDevice): VkPhysicalDeviceFeatures =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
51 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
52 device.vk.vkGetPhysicalDeviceFeatures(addr result)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
53
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
54 proc getSurfaceCapabilities*(device: PhysicalDevice): VkSurfaceCapabilitiesKHR =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
55 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
56 assert device.surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
57 checkVkResult device.vk.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device.surface, addr(result))
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
58
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
59 proc getSurfaceFormats*(device: PhysicalDevice): seq[VkSurfaceFormatKHR] =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
60 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
61 assert device.surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
62 var n_formats: uint32
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
63 checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device.vk, device.surface, addr(n_formats), nil)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
64 result = newSeq[VkSurfaceFormatKHR](n_formats)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
65 checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device.vk, device.surface, addr(n_formats), result.toCPointer)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
66
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
67 func filterSurfaceFormat*(
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
68 formats: seq[VkSurfaceFormatKHR],
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
69 imageFormat = VK_FORMAT_B8G8R8A8_SRGB,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
70 colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
71 ): VkSurfaceFormatKHR =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
72 for format in formats:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
73 if format.format == imageFormat and format.colorSpace == colorSpace:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
74 return format
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
75
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
76 proc filterSurfaceFormat*(device: PhysicalDevice): VkSurfaceFormatKHR =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
77 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
78 assert device.surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
79 device.getSurfaceFormats().filterSurfaceFormat()
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
80
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
81 proc getSurfacePresentModes*(device: PhysicalDevice): seq[VkPresentModeKHR] =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
82 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
83 assert device.surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
84 var n_modes: uint32
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
85 checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device.vk, device.surface, addr(n_modes), nil)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
86 result = newSeq[VkPresentModeKHR](n_modes)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
87 checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device.vk, device.surface, addr(n_modes), result.toCPointer)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
88
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
89 proc getQueueFamilies*(device: PhysicalDevice): seq[QueueFamily] =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
90 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
91 var nQueuefamilies: uint32
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
92 vkGetPhysicalDeviceQueueFamilyProperties(device.vk, addr nQueuefamilies, nil)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
93 var queuFamilies = newSeq[VkQueueFamilyProperties](nQueuefamilies)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
94 vkGetPhysicalDeviceQueueFamilyProperties(device.vk, addr nQueuefamilies , queuFamilies.toCPointer)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
95 for i in 0 ..< nQueuefamilies:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
96 result.add QueueFamily(
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
97 device: device,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
98 properties: queuFamilies[i],
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
99 index: i,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
100 flags: queuFamilies[i].queueFlags.toEnums,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
101 )
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
102
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
103 proc hasGraphics*(family: QueueFamily): bool =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
104 VK_QUEUE_GRAPHICS_BIT in family.flags
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
105 proc hasPresentation*(family: QueueFamily, surface: VkSurfaceKHR): bool =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
106 assert surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
107 var presentation = VkBool32(false)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
108 checkVkResult vkGetPhysicalDeviceSurfaceSupportKHR(family.device.vk, family.index, surface, addr presentation)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
109 return presentation
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
110
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
111 proc filterForGraphicsPresentationQueues*(device: PhysicalDevice): seq[QueueFamily] =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
112 var hasGraphics = false
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
113 var hasPresentation = false
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
114 var queues: Table[uint32, QueueFamily]
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
115 for family in device.getQueueFamilies():
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
116 if family.hasGraphics:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
117 queues[family.index] = family
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
118 hasGraphics = true
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
119 if family.hasPresentation(device.surface):
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
120 queues[family.index] = family
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
121 hasPresentation = true
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
122 if hasGraphics and hasPresentation:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
123 return queues.values.toSeq
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
124
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
125 proc filterGraphics(families: seq[QueueFamily]): seq[QueueFamily] =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
126 for family in families:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
127 if family.hasGraphics:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
128 result.add family
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
129
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
130 proc filterPresentation(families: seq[QueueFamily], surface: VkSurfaceKHR): seq[QueueFamily] =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
131 assert surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
132 for family in families:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
133 if family.hasPresentation(surface):
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
134 result.add family
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
135
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
136 proc rateGraphics*(device: PhysicalDevice): float =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
137 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
138 assert device.surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
139 if device.getQueueFamilies().filterGraphics().filterPresentation(device.surface).len == 0:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
140 return -1
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
141 if not ("VK_KHR_swapchain" in device.getExtensions()):
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
142 return -1
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
143 const deviceTypeMap = [
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
144 VK_PHYSICAL_DEVICE_TYPE_OTHER,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
145 VK_PHYSICAL_DEVICE_TYPE_CPU,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
146 VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
147 VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
148 VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
149 ]
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
150 for (i, devicetype) in enumerate(deviceTypeMap):
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
151 if device.devicetype == devicetype:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
152 result = float(i)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
153
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
154 proc filterBestGraphics*(devices: seq[PhysicalDevice]): PhysicalDevice =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
155 var bestVal = -1'f
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
156 for device in devices:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
157 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
158 assert device.surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
159 let rating = device.rateGraphics()
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
160 if rating > bestVal:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
161 bestVal = rating
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
162 result = device
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
163 assert bestVal >= 0