MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ pick_physical_device()

bool MayaFlux::Core::VKDevice::pick_physical_device ( vk::Instance  instance,
vk::SurfaceKHR  temp_surface 
)
private

Pick a suitable physical device (GPU)

Parameters
instanceVulkan instance
temp_surfaceTemporary surface for presentation support checks
Returns
true if a suitable device was found

Definition at line 72 of file VKDevice.cpp.

73{
74 vk::Instance vk_instance(instance);
75 auto devices = vk_instance.enumeratePhysicalDevices();
76
77 if (devices.empty()) {
79 std::source_location::current(),
80 "Failed to find GPUs with Vulkan support!");
81 }
82
83 for (const auto& device : devices) {
84 QueueFamilyIndices indices = find_queue_families(device, nullptr);
85
86 if (indices.graphics_family.has_value()) {
87 auto available_extensions = device.enumerateDeviceExtensionProperties();
88 bool supports_swapchain = false;
89 bool supports_mesh_shader = false;
90
91 for (const auto& ext : available_extensions) {
92 if (strcmp(ext.extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
93 supports_swapchain = true;
94 }
95 if (strcmp(ext.extensionName, VK_EXT_MESH_SHADER_EXTENSION_NAME) == 0) {
96 supports_mesh_shader = true;
97 }
98 }
99
100 if (!supports_swapchain) {
102 "Physical device {} does not support VK_KHR_swapchain - skipping",
103 device.getProperties().deviceName.data());
104 continue;
105 }
106
107 if (!supports_mesh_shader) {
109 "Physical device {} does not support VK_EXT_mesh_shader - "
110 "mesh shading features will be unavailable",
111 device.getProperties().deviceName.data());
112 } else {
113 vk::PhysicalDeviceMeshShaderFeaturesEXT mesh_features;
114 vk::PhysicalDeviceFeatures2 temp_features;
115 temp_features.pNext = &mesh_features;
116 device.getFeatures2(&temp_features);
117
118 if (mesh_features.meshShader == VK_FALSE || mesh_features.taskShader == VK_FALSE) {
120 "Physical device {} supports VK_EXT_mesh_shader extension but features disabled",
121 device.getProperties().deviceName.data());
122 supports_mesh_shader = false;
123 }
124 }
125
126 m_physical_device = device;
127 m_queue_families = indices;
128 m_supports_mesh_shaders = supports_mesh_shader;
129
130 vk::PhysicalDeviceProperties props = device.getProperties();
132 "Selected GPU: {}", props.deviceName.data());
133 return true;
134 }
135 }
136
138 std::source_location::current(),
139 "Failed to find a suitable GPU!");
140 return false;
141}
#define MF_INFO(comp, ctx,...)
#define MF_PRINT(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
bool m_supports_mesh_shaders
Whether the device supports mesh shaders.
Definition VKDevice.hpp:151
vk::PhysicalDevice m_physical_device
Selected physical device (GPU)
Definition VKDevice.hpp:115
QueueFamilyIndices find_queue_families(vk::PhysicalDevice device, vk::SurfaceKHR surface=nullptr)
Find queue families on the given physical device.
Definition VKDevice.cpp:143
QueueFamilyIndices m_queue_families
Indices of required queue families.
Definition VKDevice.hpp:122
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.

References MayaFlux::Journal::Core, find_queue_families(), MayaFlux::Core::QueueFamilyIndices::graphics_family, MayaFlux::Journal::GraphicsBackend, m_physical_device, m_queue_families, m_supports_mesh_shaders, MF_INFO, MF_PRINT, and MF_WARN.

Referenced by initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: