VulkanDevice: Actually allow enumeration of 1.0 device

This commit is contained in:
Stenzek 2023-12-25 23:02:13 +10:00
parent c233eb53ab
commit 46e0afd2d4
No known key found for this signature in database
2 changed files with 21 additions and 30 deletions

View file

@ -127,8 +127,8 @@ GPUTexture::Format VulkanDevice::GetFormatForVkFormat(VkFormat format)
return GPUTexture::Format::Unknown; return GPUTexture::Format::Unknown;
} }
VkInstance VulkanDevice::CreateVulkanInstance(const WindowInfo& wi, u32* apiVersion, OptionalExtensions* oe, VkInstance VulkanDevice::CreateVulkanInstance(const WindowInfo& wi, OptionalExtensions* oe, bool enable_debug_utils,
bool enable_debug_utils, bool enable_validation_layer) bool enable_validation_layer)
{ {
ExtensionList enabled_extensions; ExtensionList enabled_extensions;
if (!SelectInstanceExtensions(&enabled_extensions, wi, oe, enable_debug_utils)) if (!SelectInstanceExtensions(&enabled_extensions, wi, oe, enable_debug_utils))
@ -150,10 +150,10 @@ VkInstance VulkanDevice::CreateVulkanInstance(const WindowInfo& wi, u32* apiVers
} }
// Cap out at 1.1 for consistency. // Cap out at 1.1 for consistency.
*apiVersion = std::min(maxApiVersion, VK_API_VERSION_1_1); const u32 apiVersion = std::min(maxApiVersion, VK_API_VERSION_1_1);
Log_InfoFmt("Supported instance version: {}.{}.{}, requesting version {}.{}.{}", VK_API_VERSION_MAJOR(maxApiVersion), Log_InfoFmt("Supported instance version: {}.{}.{}, requesting version {}.{}.{}", VK_API_VERSION_MAJOR(maxApiVersion),
VK_API_VERSION_MINOR(maxApiVersion), VK_API_VERSION_PATCH(maxApiVersion), VK_API_VERSION_MINOR(maxApiVersion), VK_API_VERSION_PATCH(maxApiVersion),
VK_API_VERSION_MAJOR(*apiVersion), VK_API_VERSION_MINOR(*apiVersion), VK_API_VERSION_PATCH(*apiVersion)); VK_API_VERSION_MAJOR(apiVersion), VK_API_VERSION_MINOR(apiVersion), VK_API_VERSION_PATCH(apiVersion));
// Remember to manually update this every release. We don't pull in svnrev.h here, because // Remember to manually update this every release. We don't pull in svnrev.h here, because
// it's only the major/minor version, and rebuilding the file every time something else changes // it's only the major/minor version, and rebuilding the file every time something else changes
@ -165,7 +165,7 @@ VkInstance VulkanDevice::CreateVulkanInstance(const WindowInfo& wi, u32* apiVers
app_info.applicationVersion = VK_MAKE_VERSION(0, 1, 0); app_info.applicationVersion = VK_MAKE_VERSION(0, 1, 0);
app_info.pEngineName = "DuckStation"; app_info.pEngineName = "DuckStation";
app_info.engineVersion = VK_MAKE_VERSION(0, 1, 0); app_info.engineVersion = VK_MAKE_VERSION(0, 1, 0);
app_info.apiVersion = *apiVersion; app_info.apiVersion = apiVersion;
VkInstanceCreateInfo instance_create_info = {}; VkInstanceCreateInfo instance_create_info = {};
instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
@ -307,16 +307,6 @@ VulkanDevice::GPUList VulkanDevice::EnumerateGPUs(VkInstance instance)
VkPhysicalDeviceProperties props = {}; VkPhysicalDeviceProperties props = {};
vkGetPhysicalDeviceProperties(device, &props); vkGetPhysicalDeviceProperties(device, &props);
// Skip GPUs which don't support Vulkan 1.1, since we won't be able to create a device with them anyway.
if (VK_API_VERSION_VARIANT(props.apiVersion) == 0 && VK_API_VERSION_MAJOR(props.apiVersion) <= 1 &&
VK_API_VERSION_MINOR(props.apiVersion) < 1)
{
Log_WarningFmt("Ignoring Vulkan GPU '{}' because it only claims support for Vulkan {}.{}.{}", props.deviceName,
VK_API_VERSION_MAJOR(props.apiVersion), VK_API_VERSION_MINOR(props.apiVersion),
VK_API_VERSION_PATCH(props.apiVersion));
continue;
}
std::string gpu_name = props.deviceName; std::string gpu_name = props.deviceName;
// handle duplicate adapter names // handle duplicate adapter names
@ -668,8 +658,15 @@ void VulkanDevice::ProcessDeviceExtensions()
m_optional_extensions.vk_khr_push_descriptor ? "supported" : "NOT supported"); m_optional_extensions.vk_khr_push_descriptor ? "supported" : "NOT supported");
} }
bool VulkanDevice::CreateAllocator(u32 apiVersion) bool VulkanDevice::CreateAllocator()
{ {
const u32 apiVersion = std::min(m_device_properties.apiVersion, VK_API_VERSION_1_1);
Log_InfoFmt("Supported device API version: {}.{}.{}, using version {}.{}.{} for allocator.",
VK_API_VERSION_MAJOR(m_device_properties.apiVersion),
VK_API_VERSION_MINOR(m_device_properties.apiVersion),
VK_API_VERSION_PATCH(m_device_properties.apiVersion), VK_API_VERSION_MAJOR(apiVersion),
VK_API_VERSION_MINOR(apiVersion), VK_API_VERSION_PATCH(apiVersion));
VmaAllocatorCreateInfo ci = {}; VmaAllocatorCreateInfo ci = {};
ci.vulkanApiVersion = apiVersion; ci.vulkanApiVersion = apiVersion;
ci.flags = VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT; ci.flags = VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT;
@ -1769,9 +1766,8 @@ GPUDevice::AdapterAndModeList VulkanDevice::StaticGetAdapterAndModeList()
if (Vulkan::LoadVulkanLibrary()) if (Vulkan::LoadVulkanLibrary())
{ {
ScopedGuard lib_guard([]() { Vulkan::UnloadVulkanLibrary(); }); ScopedGuard lib_guard([]() { Vulkan::UnloadVulkanLibrary(); });
u32 apiVersion;
OptionalExtensions oe = {}; OptionalExtensions oe = {};
const VkInstance instance = CreateVulkanInstance(WindowInfo(), &apiVersion, &oe, false, false); const VkInstance instance = CreateVulkanInstance(WindowInfo(), &oe, false, false);
if (instance != VK_NULL_HANDLE) if (instance != VK_NULL_HANDLE)
{ {
if (Vulkan::LoadVulkanInstanceFunctions(instance)) if (Vulkan::LoadVulkanInstanceFunctions(instance))
@ -1853,9 +1849,7 @@ bool VulkanDevice::CreateDevice(const std::string_view& adapter, bool threaded_p
return false; return false;
} }
u32 apiVersion; m_instance = CreateVulkanInstance(m_window_info, &m_optional_extensions, enable_debug_utils, enable_validation_layer);
m_instance = CreateVulkanInstance(m_window_info, &apiVersion, &m_optional_extensions, enable_debug_utils,
enable_validation_layer);
if (m_instance == VK_NULL_HANDLE) if (m_instance == VK_NULL_HANDLE)
{ {
if (enable_debug_utils || enable_validation_layer) if (enable_debug_utils || enable_validation_layer)
@ -1863,8 +1857,8 @@ bool VulkanDevice::CreateDevice(const std::string_view& adapter, bool threaded_p
// Try again without the validation layer. // Try again without the validation layer.
enable_debug_utils = false; enable_debug_utils = false;
enable_validation_layer = false; enable_validation_layer = false;
m_instance = CreateVulkanInstance(m_window_info, &apiVersion, &m_optional_extensions, enable_debug_utils, m_instance =
enable_validation_layer); CreateVulkanInstance(m_window_info, &m_optional_extensions, enable_debug_utils, enable_validation_layer);
if (m_instance == VK_NULL_HANDLE) if (m_instance == VK_NULL_HANDLE)
{ {
Host::ReportErrorAsync("Error", Host::ReportErrorAsync("Error",
@ -1953,11 +1947,8 @@ bool VulkanDevice::CreateDevice(const std::string_view& adapter, bool threaded_p
} }
// And critical resources. // And critical resources.
if (!CreateAllocator(apiVersion) || !CreatePersistentDescriptorPool() || !CreateCommandBuffers() || if (!CreateAllocator() || !CreatePersistentDescriptorPool() || !CreateCommandBuffers() || !CreatePipelineLayouts())
!CreatePipelineLayouts())
{
return false; return false;
}
if (threaded_presentation) if (threaded_presentation)
StartPresentThread(); StartPresentThread();

View file

@ -283,8 +283,8 @@ private:
static void GetAdapterAndModeList(AdapterAndModeList* ret, VkInstance instance); static void GetAdapterAndModeList(AdapterAndModeList* ret, VkInstance instance);
// Helper method to create a Vulkan instance. // Helper method to create a Vulkan instance.
static VkInstance CreateVulkanInstance(const WindowInfo& wi, u32* apiVersion, OptionalExtensions* oe, static VkInstance CreateVulkanInstance(const WindowInfo& wi, OptionalExtensions* oe, bool enable_debug_utils,
bool enable_debug_utils, bool enable_validation_layer); bool enable_validation_layer);
// Returns a list of Vulkan-compatible GPUs. // Returns a list of Vulkan-compatible GPUs.
using GPUList = std::vector<std::pair<VkPhysicalDevice, std::string>>; using GPUList = std::vector<std::pair<VkPhysicalDevice, std::string>>;
@ -321,7 +321,7 @@ private:
bool CheckFeatures(FeatureMask disabled_features); bool CheckFeatures(FeatureMask disabled_features);
bool CreateAllocator(u32 apiVersion); bool CreateAllocator();
void DestroyAllocator(); void DestroyAllocator();
bool CreateCommandBuffers(); bool CreateCommandBuffers();
void DestroyCommandBuffers(); void DestroyCommandBuffers();