Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: score gpu and rank before check physical device suitability to find the best gpu for rending #29

Merged
merged 4 commits into from
Apr 5, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Format: Fomat changed file with clang-format file
  • Loading branch information
CRAFTSTARCN committed Apr 5, 2022
commit 575acde184036d2def092d9eb5635644364658db
Original file line number Diff line number Diff line change
Expand Up @@ -323,24 +323,28 @@ void Pilot::PVulkanContext::initializePhysicalDevice()
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) {
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) {
if (physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest following the algorithm of VulkanTutorial, not just considering the device type, but also including the limits, features

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see taht. In my previous project (doing that while learning with Vulkan Tutorial) I will enumrate all the features to score gpu, I don't know if that's better.

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

ranked_physical_devices.push_back({score,device});
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());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass a lambda function to std::sort to eliminate the std::reverse function call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done that, thaks for corrected my mistacks about format and coding style


for (const auto& device : ranked_physical_devices)
{
if (isDeviceSuitable(device.second))
Expand Down