MCPcopy Create free account
hub / github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator / SelectPhysicalDevice

Method SelectPhysicalDevice

src/VulkanSample.cpp:562–609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

560}
561
562VkPhysicalDevice VulkanUsage::SelectPhysicalDevice(const GPUSelection& GPUSelection) const
563{
564 uint32_t deviceCount = 0;
565 ERR_GUARD_VULKAN(vkEnumeratePhysicalDevices(g_hVulkanInstance, &deviceCount, nullptr));
566 std::vector<VkPhysicalDevice> physicalDevices(deviceCount);
567 if(deviceCount > 0)
568 {
569 ERR_GUARD_VULKAN(vkEnumeratePhysicalDevices(g_hVulkanInstance, &deviceCount, physicalDevices.data()));
570 }
571
572 if(GPUSelection.Index != UINT32_MAX)
573 {
574 // Cannot specify both index and name.
575 if(!GPUSelection.Substring.empty())
576 {
577 return VK_NULL_HANDLE;
578 }
579
580 return GPUSelection.Index < deviceCount ? physicalDevices[GPUSelection.Index] : VK_NULL_HANDLE;
581 }
582
583 if(!GPUSelection.Substring.empty())
584 {
585 VkPhysicalDevice result = VK_NULL_HANDLE;
586 std::wstring name;
587 for(uint32_t i = 0; i < deviceCount; ++i)
588 {
589 VkPhysicalDeviceProperties props = {};
590 vkGetPhysicalDeviceProperties(physicalDevices[i], &props);
591 if(ConvertCharsToUnicode(&name, props.deviceName, strlen(props.deviceName), CP_UTF8) &&
592 StrStrI(name.c_str(), GPUSelection.Substring.c_str()))
593 {
594 // Second matching device found - error.
595 if(result != VK_NULL_HANDLE)
596 {
597 return VK_NULL_HANDLE;
598 }
599 // First matching device found.
600 result = physicalDevices[i];
601 }
602 }
603 // Found or not, return it.
604 return result;
605 }
606
607 // Select first one.
608 return deviceCount > 0 ? physicalDevices[0] : VK_NULL_HANDLE;
609}
610
611void VulkanUsage::RegisterDebugCallbacks()
612{

Callers 1

Main2Function · 0.80

Calls 3

ConvertCharsToUnicodeFunction · 0.85
dataMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected