MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / init

Method init

framework/core/device.h:622–782  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

620
621template <vkb::BindingType bindingType>
622inline void Device<bindingType>::init(std::unordered_map<const char *, bool> const &requested_extensions, std::function<void(vkb::core::PhysicalDevice<bindingType> &)> request_gpu_features)
623{
624 LOGI("Selected GPU: {}", *gpu.get_properties().deviceName);
625
626 // Prepare the device queues
627 std::vector<vk::QueueFamilyProperties> queue_family_properties = gpu.get_queue_family_properties();
628 std::vector<vk::DeviceQueueCreateInfo> queue_create_infos;
629 std::vector<std::vector<float>> queue_priorities;
630
631 queue_create_infos.reserve(queue_family_properties.size());
632 queue_priorities.reserve(queue_family_properties.size());
633 for (uint32_t queue_family_index = 0U; queue_family_index < queue_family_properties.size(); ++queue_family_index)
634 {
635 auto const &queue_family_property = queue_family_properties[queue_family_index];
636
637 queue_priorities.push_back(std::vector<float>(queue_family_property.queueCount, 0.5f));
638 if (gpu.has_high_priority_graphics_queue() &&
639 (vkb::common::get_queue_family_index(queue_family_properties, vk::QueueFlagBits::eGraphics) == queue_family_index))
640 {
641 queue_priorities.back()[0] = 0.5f;
642 }
643
644 queue_create_infos.push_back({.queueFamilyIndex = queue_family_index,
645 .queueCount = queue_family_property.queueCount,
646 .pQueuePriorities = queue_priorities[queue_family_index].data()});
647 }
648
649 // Check extensions to enable Vma Dedicated Allocation
650 bool can_get_memory_requirements = gpu.is_extension_supported("VK_KHR_get_memory_requirements2");
651 bool has_dedicated_allocation = gpu.is_extension_supported("VK_KHR_dedicated_allocation");
652
653 if (can_get_memory_requirements && has_dedicated_allocation)
654 {
655 enabled_extensions.push_back("VK_KHR_get_memory_requirements2");
656 enabled_extensions.push_back("VK_KHR_dedicated_allocation");
657
658 LOGI("Dedicated Allocation enabled");
659 }
660
661 // For performance queries, we also use host query reset since queryPool resets cannot
662 // live in the same command buffer as beginQuery
663 if (gpu.is_extension_supported("VK_KHR_performance_query") &&
664 gpu.is_extension_supported("VK_EXT_host_query_reset"))
665 {
666 auto perf_counter_features = gpu.get_extension_features<vk::PhysicalDevicePerformanceQueryFeaturesKHR>();
667 auto host_query_reset_features = gpu.get_extension_features<vk::PhysicalDeviceHostQueryResetFeatures>();
668
669 if (perf_counter_features.performanceCounterQueryPools && host_query_reset_features.hostQueryReset)
670 {
671 gpu.add_extension_features<vk::PhysicalDevicePerformanceQueryFeaturesKHR>().performanceCounterQueryPools = VK_TRUE;
672 gpu.add_extension_features<vk::PhysicalDeviceHostQueryResetFeatures>().hostQueryReset = VK_TRUE;
673 enabled_extensions.push_back("VK_KHR_performance_query");
674 enabled_extensions.push_back("VK_EXT_host_query_reset");
675 LOGI("Performance query enabled");
676 }
677 }
678
679 // Check that extensions are supported before trying to create the device

Callers 6

prepareMethod · 0.45
InstanceMethod · 0.45
init_deviceMethod · 0.45
init_instanceMethod · 0.45
create_deviceMethod · 0.45
create_instanceMethod · 0.45

Calls 12

VulkanExceptionClass · 0.85
sizeMethod · 0.80
endMethod · 0.80
set_handleMethod · 0.80
initFunction · 0.70
get_queue_family_indexFunction · 0.50
get_handleMethod · 0.45
resizeMethod · 0.45
get_family_indexMethod · 0.45

Tested by

no test coverage detected