vk: Fix cyclic dependency problem during physical device init

This commit is contained in:
kd-11 2025-05-03 14:26:34 +03:00 committed by Megamouse
parent 5cfa9fd83e
commit e67beb27dd
2 changed files with 81 additions and 55 deletions

View file

@ -158,13 +158,46 @@ namespace vk
} }
} }
void physical_device::get_physical_device_properties(bool allow_extensions) void physical_device::get_physical_device_properties_0(bool allow_extensions)
{ {
// Core properties only
vkGetPhysicalDeviceMemoryProperties(dev, &memory_properties); vkGetPhysicalDeviceMemoryProperties(dev, &memory_properties);
vkGetPhysicalDeviceProperties(dev, &props);
if (!allow_extensions) if (!allow_extensions)
{ {
vkGetPhysicalDeviceProperties(dev, &props); return;
}
// Try to query driver properties if possible
supported_extensions instance_extensions(supported_extensions::instance);
supported_extensions device_extensions(supported_extensions::device, nullptr, dev);
if (!instance_extensions.is_supported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME) ||
!device_extensions.is_supported(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME))
{
return;
}
VkPhysicalDeviceProperties2KHR properties2;
properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
properties2.pNext = nullptr;
driver_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR;
driver_properties.pNext = properties2.pNext;
properties2.pNext = &driver_properties;
auto _vkGetPhysicalDeviceProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2KHR>(vkGetInstanceProcAddr(parent, "vkGetPhysicalDeviceProperties2KHR"));
ensure(_vkGetPhysicalDeviceProperties2KHR);
_vkGetPhysicalDeviceProperties2KHR(dev, &properties2);
}
void physical_device::get_physical_device_properties_1(bool allow_extensions)
{
// Extended properties. Call after checking for features
if (!allow_extensions)
{
return; return;
} }
@ -173,10 +206,9 @@ namespace vk
if (!instance_extensions.is_supported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) if (!instance_extensions.is_supported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME))
{ {
vkGetPhysicalDeviceProperties(dev, &props); return;
} }
else
{
VkPhysicalDeviceProperties2KHR properties2; VkPhysicalDeviceProperties2KHR properties2;
properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR; properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
properties2.pNext = nullptr; properties2.pNext = nullptr;
@ -198,13 +230,6 @@ namespace vk
properties2.pNext = &multidraw_props; properties2.pNext = &multidraw_props;
} }
if (device_extensions.is_supported(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME))
{
driver_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR;
driver_properties.pNext = properties2.pNext;
properties2.pNext = &driver_properties;
}
auto _vkGetPhysicalDeviceProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2KHR>(vkGetInstanceProcAddr(parent, "vkGetPhysicalDeviceProperties2KHR")); auto _vkGetPhysicalDeviceProperties2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2KHR>(vkGetInstanceProcAddr(parent, "vkGetPhysicalDeviceProperties2KHR"));
ensure(_vkGetPhysicalDeviceProperties2KHR); ensure(_vkGetPhysicalDeviceProperties2KHR);
@ -236,15 +261,15 @@ namespace vk
} }
} }
} }
}
void physical_device::create(VkInstance context, VkPhysicalDevice pdev, bool allow_extensions) void physical_device::create(VkInstance context, VkPhysicalDevice pdev, bool allow_extensions)
{ {
dev = pdev; dev = pdev;
parent = context; parent = context;
get_physical_device_properties_0(allow_extensions);
get_physical_device_features(allow_extensions); get_physical_device_features(allow_extensions);
get_physical_device_properties(allow_extensions); get_physical_device_properties_1(allow_extensions);
rsx_log.always()("Found Vulkan-compatible GPU: '%s' running on driver %s", get_name(), get_driver_version()); rsx_log.always()("Found Vulkan-compatible GPU: '%s' running on driver %s", get_name(), get_driver_version());

View file

@ -106,7 +106,8 @@ namespace vk
friend class render_device; friend class render_device;
private: private:
void get_physical_device_features(bool allow_extensions); void get_physical_device_features(bool allow_extensions);
void get_physical_device_properties(bool allow_extensions); void get_physical_device_properties_0(bool allow_extensions);
void get_physical_device_properties_1(bool allow_extensions);
public: public: