Implement GPU auto selection, preferring discrete over integrated

This commit is contained in:
2021-05-02 18:31:53 -07:00
parent 76b7e64ae6
commit 2385a19926
2 changed files with 21 additions and 5 deletions

View File

@@ -924,7 +924,7 @@ KrResult KRContext::createWindowSurface(const KrCreateWindowSurfaceInfo* createW
int selectedDeviceGraphicsFamilyQueue = -1; int selectedDeviceGraphicsFamilyQueue = -1;
int selectedDevicePresentFamilyQueue = -1; int selectedDevicePresentFamilyQueue = -1;
for (const auto& device : devices) { for (const VkPhysicalDevice& device : devices) {
VkPhysicalDeviceProperties deviceProperties; VkPhysicalDeviceProperties deviceProperties;
VkPhysicalDeviceFeatures deviceFeatures; VkPhysicalDeviceFeatures deviceFeatures;
vkGetPhysicalDeviceProperties(device, &deviceProperties); vkGetPhysicalDeviceProperties(device, &deviceProperties);
@@ -976,14 +976,28 @@ KrResult KRContext::createWindowSurface(const KrCreateWindowSurfaceInfo* createW
continue; continue;
} }
// This one will work bool bestDevice = false;
if (info.device == VK_NULL_HANDLE) { if (info.device == VK_NULL_HANDLE) {
bestDevice = true;
}
else if (info.deviceProperties.deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) {
// Discrete GPU's are always the best choice
bestDevice = true;
}
else if (info.deviceProperties.deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) {
// Integrated GPU's are the second best choice
bestDevice = true;
} else if (info.deviceProperties.deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && info.deviceProperties.deviceType != VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU && deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU) {
// Virtual GPU's are the 3rd best choice
bestDevice = true;
}
// TODO - We should resolve any remaining options based on user preference
if (bestDevice) {
info.device = device; info.device = device;
info.deviceProperties = deviceProperties;
info.deviceFeatures = deviceFeatures;
selectedDeviceGraphicsFamilyQueue = graphicsFamilyQueue; selectedDeviceGraphicsFamilyQueue = graphicsFamilyQueue;
selectedDevicePresentFamilyQueue = presentFamilyQueue; selectedDevicePresentFamilyQueue = presentFamilyQueue;
} else {
// We need to choose the best one...
// TODO - Implement
} }
} }
if (info.device == VK_NULL_HANDLE) { if (info.device == VK_NULL_HANDLE) {

View File

@@ -182,6 +182,8 @@ private:
VkSurfaceKHR surface; VkSurfaceKHR surface;
VkPhysicalDevice device; VkPhysicalDevice device;
VkDevice logicalDevice; VkDevice logicalDevice;
VkPhysicalDeviceProperties deviceProperties;
VkPhysicalDeviceFeatures deviceFeatures;
VkQueue graphicsQueue; VkQueue graphicsQueue;
VkQueue presentQueue; VkQueue presentQueue;
VkSwapchainKHR swapChain; VkSwapchainKHR swapChain;