Skip to content

Commit

Permalink
Select vulkan device that supports most extensions. (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe authored Dec 19, 2024
1 parent b5e49c6 commit de63f1d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/vulkan/vk-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,11 @@ Result DeviceImpl::initVulkanInstanceAndDevice(const NativeHandle* handles, bool
);

// Use first physical device by default.
Index selectedDeviceIndex = 0;
Index selectedDeviceIndex = -1;

// Search for requested adapter.
if (m_desc.adapterLUID)
{
selectedDeviceIndex = -1;
for (Index i = 0; i < physicalDevices.size(); ++i)
{
if (vk::getAdapterLUID(m_api, physicalDevices[i]) == *m_desc.adapterLUID)
Expand All @@ -336,6 +335,24 @@ Result DeviceImpl::initVulkanInstanceAndDevice(const NativeHandle* handles, bool
return SLANG_E_NOT_FOUND;
}

if (selectedDeviceIndex == -1)
{
// If no device is explicitly selected by the user,
// we will select the device with most amount of extensions.
selectedDeviceIndex = 0;
uint32_t currentMaxExtensionCount = 0;
for (Index i = 0; i < physicalDevices.size(); ++i)
{
uint32_t propCount = 0;
m_api.vkEnumerateDeviceExtensionProperties(physicalDevices[i], NULL, &propCount, nullptr);
if (propCount > currentMaxExtensionCount)
{
selectedDeviceIndex = i;
currentMaxExtensionCount = propCount;
}
}
}

if (selectedDeviceIndex >= physicalDevices.size())
return SLANG_FAIL;

Expand Down

0 comments on commit de63f1d

Please sign in to comment.