Skip to content

Commit

Permalink
Sort drivers that emulate vulkan via a different graphics API last
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed Jan 26, 2024
1 parent a1e6c90 commit 5ad8b49
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/zvulkan/vulkaninstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class VulkanDeviceProperties
VkPhysicalDeviceMemoryProperties Memory = {};
VkPhysicalDeviceAccelerationStructurePropertiesKHR AccelerationStructure = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_PROPERTIES_KHR };
VkPhysicalDeviceDescriptorIndexingProperties DescriptorIndexing = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT };
VkPhysicalDeviceLayeredDriverPropertiesMSFT LayeredDriver = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LAYERED_DRIVER_PROPERTIES_MSFT };
};

class VulkanPhysicalDevice
Expand Down
6 changes: 6 additions & 0 deletions src/vulkanbuilders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,12 @@ std::vector<VulkanCompatibleDevice> VulkanDeviceBuilder::FindDevices(const std::
if (sortA != sortB)
return sortA < sortB;

// Any driver that is emulating vulkan (i.e. via Direct3D 12) should only be chosen as the last option within each GPU type
sortA = a.Device->Properties.LayeredDriver.underlyingAPI;
sortB = b.Device->Properties.LayeredDriver.underlyingAPI;
if (sortA != sortB)
return sortA < sortB;

// Then sort by the device's unique ID so that vk_device uses a consistent order
int sortUUID = memcmp(a.Device->Properties.Properties.pipelineCacheUUID, b.Device->Properties.Properties.pipelineCacheUUID, VK_UUID_SIZE);
return sortUUID < 0;
Expand Down
6 changes: 6 additions & 0 deletions src/vulkaninstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,17 @@ std::vector<VulkanPhysicalDevice> VulkanInstance::GetPhysicalDevices(VkInstance
*next = &dev.Properties.DescriptorIndexing;
next = &dev.Properties.DescriptorIndexing.pNext;
}
if (checkForExtension(VK_MSFT_LAYERED_DRIVER_EXTENSION_NAME))
{
*next = &dev.Properties.LayeredDriver;
next = &dev.Properties.LayeredDriver.pNext;
}

vkGetPhysicalDeviceProperties2(dev.Device, &deviceProperties2);
dev.Properties.Properties = deviceProperties2.properties;
dev.Properties.AccelerationStructure.pNext = nullptr;
dev.Properties.DescriptorIndexing.pNext = nullptr;
dev.Properties.LayeredDriver.pNext = nullptr;

VkPhysicalDeviceFeatures2 deviceFeatures2 = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2 };

Expand Down

0 comments on commit 5ad8b49

Please sign in to comment.