The gpu_info file contains several functions which could be useful if there's an issue with someone using our code. It can print the available gpus and all kind of data associated with them. The problem is that it doesn't print anything anymore. The reason for this is that during my refactoring, I used the reserve method instead of the resize method (or calling the std::vector with a number of elements in its constructor, which essentially constructs the elements, being equivalent to .resize()).
So this code is wrong:
void print_all_physical_devices(const VkInstance instance, const VkSurfaceKHR surface) {
assert(instance);
assert(surface);
std::uint32_t gpu_count{0};
// Query how many graphics cards are available.
if (const auto result = vkEnumeratePhysicalDevices(instance, &gpu_count, nullptr); result != VK_SUCCESS) {
spdlog::error("Error: vkEnumeratePhysicalDevices returned {}!", vk_tools::as_string(result));
return;
}
spdlog::trace("Number of available gpus: {}", gpu_count);
if (gpu_count == 0) {
return;
}
std::vector<VkPhysicalDevice> available_gpus;
available_gpus.reserve(gpu_count); // THIS IS WRONG!!!
// Store all available graphics cards.
if (const auto result = vkEnumeratePhysicalDevices(instance, &gpu_count, available_gpus.data());
result != VK_SUCCESS) {
spdlog::error("Error: vkEnumeratePhysicalDevices returned {}!", vk_tools::as_string(result));
return;
}
/// more going on below from here...
}
It should really be std::vector<VkPhysicalDevice> available_gpus(gpu_count);
or change the .reserve to .resize.
Since this is a very common mistake always remember: reserve doesn't create any objects and doesn't call any constructors!
Steps To Reproduce
Just run the current main branch and add a debug break in print_all_physical_devices.
Describe The Bug
The
gpu_info
file contains several functions which could be useful if there's an issue with someone using our code. It can print the available gpus and all kind of data associated with them. The problem is that it doesn't print anything anymore. The reason for this is that during my refactoring, I used the reserve method instead of the resize method (or calling the std::vector with a number of elements in its constructor, which essentially constructs the elements, being equivalent to .resize()).So this code is wrong:
It should really be
std::vector<VkPhysicalDevice> available_gpus(gpu_count);
or change the.reserve
to.resize
.Since this is a very common mistake always remember:
reserve
doesn't create any objects and doesn't call any constructors!Steps To Reproduce
Just run the current main branch and add a debug break in
print_all_physical_devices
.Expected Behavior
It should print all the available info
Affected Code
gpu_info.cpp
Operating System
All
Application Version
4f7b8377e5ed91e85db9f040527f33127d247c31
Additional Context
None
Relevant Log Output