Repository: BoomingTech/Pilot
File: engine/source/runtime/function/render/source/vulkan_manager/context/vulkan_context.cpp (C++)

Code before:
    }
}

void Pilot::PVulkanContext::initializePhysicalDevice()
{
    uint32_t physical_device_count;
    vkEnumeratePhysicalDevices(_instance, &physical_device_count, nullptr);
    if (physical_device_count == 0)
    {
        throw std::runtime_error("enumerate physical devices");
    }
    else
    {
        // find one device that matches our requirement
        // or find which is the best
        std::vector<VkPhysicalDevice> physical_devices(physical_device_count);
        vkEnumeratePhysicalDevices(_instance, &physical_device_count, physical_devices.data());

        std::vector<std::pair<int, VkPhysicalDevice>> ranked_physical_devices;
        for (const auto& device : physical_devices)
        {
            VkPhysicalDeviceProperties physical_device_properties;
            vkGetPhysicalDeviceProperties(device, &physical_device_properties);
            int score = 0;

            if (physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
            {
                score += 1000;
            }
            else if (physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
            {
                score += 100;
            }

            ranked_physical_devices.push_back({score, device});
        }

        std::sort(ranked_physical_devices.begin(), ranked_physical_devices.end());
        std::reverse(ranked_physical_devices.begin(), ranked_physical_devices.end());

        for (const auto& device : ranked_physical_devices)
        {
            if (isDeviceSuitable(device.second))
            {
                _physical_device = device.second;
                break;
            }
        }

        if (VK_NULL_HANDLE == _physical_device)
        {

Review comment (suggestion):
Suggest following the algorithm of [VulkanTutorial](https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Physical_devices_and_queue_families), not just considering the device type, but also including the limits, features

Code after:
    }
}

void Pilot::PVulkanContext::initializePhysicalDevice()
{
    uint32_t physical_device_count;
    vkEnumeratePhysicalDevices(_instance, &physical_device_count, nullptr);
    if (physical_device_count == 0)
    {
        throw std::runtime_error("enumerate physical devices");
    }
    else
    {
        // find one device that matches our requirement
        // or find which is the best
        std::vector<VkPhysicalDevice> physical_devices(physical_device_count);
        vkEnumeratePhysicalDevices(_instance, &physical_device_count, physical_devices.data());

        std::vector<std::pair<int, VkPhysicalDevice>> ranked_physical_devices;
        for (const auto& device : physical_devices)
        {
            VkPhysicalDeviceProperties physical_device_properties;
            vkGetPhysicalDeviceProperties(device, &physical_device_properties);
            int score = 0;

            if (physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
            {
                score += 1000;
            }
            else if (physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
            {
                score += 100;
            }

            ranked_physical_devices.push_back({score, device});
        }

        std::sort(ranked_physical_devices.begin(),
                  ranked_physical_devices.end(),
                  [](const std::pair<int, VkPhysicalDevice>& p1, const std::pair<int, VkPhysicalDevice>& p2) {
                      return p1 > p2;
                  });

        for (const auto& device : ranked_physical_devices)
        {
            if (isDeviceSuitable(device.second))
            {
                _physical_device = device.second;
                break;
            }
        }