annotate src/semicongine/vulkan/physicaldevice.nim @ 207:81fab407a479

add: some adjustment to the last refactoring :P
author Sam <sam@basx.dev>
date Tue, 09 May 2023 01:18:01 +0700
parents 7f921d7d0a2b
children ddfc54036e00
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
97
110ed3ee5df8 add: swapchain, images, fix some destroctors
Sam <sam@basx.dev>
parents: 96
diff changeset
1 from std/enumerate import enumerate
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
2 import std/tables
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
3 import std/sequtils
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
4
206
7f921d7d0a2b did: small refactoring of module structure
Sam <sam@basx.dev>
parents: 189
diff changeset
5 import ../core
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
6 import ./instance
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
7
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
8 type
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
9 PhysicalDevice* = object
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
10 vk*: VkPhysicalDevice
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
11 name*: string
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
12 devicetype*: VkPhysicalDeviceType
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
13 surface*: VkSurfaceKHR
188
de9dff24c422 add: image/texture creation, refactoring of some unclean parts
Sam <sam@basx.dev>
parents: 112
diff changeset
14 properties*: VkPhysicalDeviceProperties
de9dff24c422 add: image/texture creation, refactoring of some unclean parts
Sam <sam@basx.dev>
parents: 112
diff changeset
15 features*: VkPhysicalDeviceFeatures
96
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
189
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 188
diff changeset
22 func `$`*(device: PhysicalDevice): string =
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 188
diff changeset
23 "Physical device: vk=" & $device.vk & ", name=" & $device.name & ", devicetype=" & $device.devicetype
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 188
diff changeset
24
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
25 proc getPhysicalDevices*(instance: Instance): seq[PhysicalDevice] =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
26 assert instance.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
27 assert instance.surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
28 var nDevices: uint32
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
29 checkVkResult vkEnumeratePhysicalDevices(instance.vk, addr(nDevices), nil)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
30 var devices = newSeq[VkPhysicalDevice](nDevices)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
31 checkVkResult vkEnumeratePhysicalDevices(instance.vk, addr(nDevices), devices.toCPointer)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
32 for i in 0 ..< nDevices:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
33 var device = PhysicalDevice(vk: devices[i], surface: instance.surface)
188
de9dff24c422 add: image/texture creation, refactoring of some unclean parts
Sam <sam@basx.dev>
parents: 112
diff changeset
34 device.vk.vkGetPhysicalDeviceProperties(addr device.properties)
de9dff24c422 add: image/texture creation, refactoring of some unclean parts
Sam <sam@basx.dev>
parents: 112
diff changeset
35 device.vk.vkGetPhysicalDeviceFeatures(addr device.features)
de9dff24c422 add: image/texture creation, refactoring of some unclean parts
Sam <sam@basx.dev>
parents: 112
diff changeset
36 device.name = device.properties.deviceName.cleanString()
de9dff24c422 add: image/texture creation, refactoring of some unclean parts
Sam <sam@basx.dev>
parents: 112
diff changeset
37 device.devicetype = device.properties.deviceType
96
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 getSurfaceCapabilities*(device: PhysicalDevice): VkSurfaceCapabilitiesKHR =
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 assert device.surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
53 checkVkResult device.vk.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device.surface, addr(result))
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
54
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
55 proc getSurfaceFormats*(device: PhysicalDevice): seq[VkSurfaceFormatKHR] =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
56 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
57 assert device.surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
58 var n_formats: uint32
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
59 checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device.vk, device.surface, addr(n_formats), nil)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
60 result = newSeq[VkSurfaceFormatKHR](n_formats)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
61 checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device.vk, device.surface, addr(n_formats), result.toCPointer)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
62
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
63 func filterSurfaceFormat*(
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
64 formats: seq[VkSurfaceFormatKHR],
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
65 imageFormat = VK_FORMAT_B8G8R8A8_SRGB,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
66 colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
67 ): VkSurfaceFormatKHR =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
68 for format in formats:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
69 if format.format == imageFormat and format.colorSpace == colorSpace:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
70 return format
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
71
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
72 proc filterSurfaceFormat*(device: PhysicalDevice): VkSurfaceFormatKHR =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
73 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
74 assert device.surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
75 device.getSurfaceFormats().filterSurfaceFormat()
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
76
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
77 proc getSurfacePresentModes*(device: PhysicalDevice): seq[VkPresentModeKHR] =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
78 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
79 assert device.surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
80 var n_modes: uint32
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
81 checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device.vk, device.surface, addr(n_modes), nil)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
82 result = newSeq[VkPresentModeKHR](n_modes)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
83 checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device.vk, device.surface, addr(n_modes), result.toCPointer)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
84
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
85 proc getQueueFamilies*(device: PhysicalDevice): seq[QueueFamily] =
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
86 assert device.vk.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
87 var nQueuefamilies: uint32
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
88 vkGetPhysicalDeviceQueueFamilyProperties(device.vk, addr nQueuefamilies, nil)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
89 var queuFamilies = newSeq[VkQueueFamilyProperties](nQueuefamilies)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
90 vkGetPhysicalDeviceQueueFamilyProperties(device.vk, addr nQueuefamilies , queuFamilies.toCPointer)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
91 for i in 0 ..< nQueuefamilies:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
92 result.add QueueFamily(
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
93 device: device,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
94 properties: queuFamilies[i],
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
95 index: i,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
96 flags: queuFamilies[i].queueFlags.toEnums,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
97 )
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
98
112
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
99 proc canDoGraphics*(family: QueueFamily): bool =
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
100 VK_QUEUE_GRAPHICS_BIT in family.flags
112
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
101
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
102 proc canDoPresentation*(family: QueueFamily, surface: VkSurfaceKHR): bool =
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
103 assert surface.valid
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
104 var presentation = VkBool32(false)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
105 checkVkResult vkGetPhysicalDeviceSurfaceSupportKHR(family.device.vk, family.index, surface, addr presentation)
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
106 return presentation
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
107
112
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
108 proc canDoTransfer*(family: QueueFamily): bool =
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
109 VK_QUEUE_TRANSFER_BIT in family.flags
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
110
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
111 proc filterForGraphicsPresentationQueues*(device: PhysicalDevice): seq[QueueFamily] =
112
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
112 var canDoGraphics = false
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
113 var canDoPresentation = false
96
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():
112
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
116 if family.canDoGraphics:
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
117 queues[family.index] = family
112
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
118 canDoGraphics = true
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
119 if family.canDoPresentation(device.surface):
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents:
diff changeset
120 queues[family.index] = family
112
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
121 canDoPresentation = true
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
122 if canDoGraphics and canDoPresentation:
96
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:
112
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
127 if family.canDoGraphics:
96
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:
112
0c5a74885796 did: real implementation of buffer and memory, getting closer to collect shit for drawing per pipeline
Sam <sam@basx.dev>
parents: 97
diff changeset
133 if family.canDoPresentation(surface):
96
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