Skip to content

Commit

Permalink
vulkan: prefer native drivers over vulkan-on-d3d12.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Feb 2, 2025
1 parent cc88b94 commit 0e5133e
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions src/modules/graphics/vulkan/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,37 @@ int Graphics::rateDeviceSuitability(VkPhysicalDevice device, bool querySwapChain
vkGetPhysicalDeviceProperties(device, &deviceProperties);
vkGetPhysicalDeviceFeatures(device, &deviceFeatures);

int score = 1;
uint32_t extensionCount = 0;
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr);

std::vector<VkExtensionProperties> availableExtensions(extensionCount);
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, availableExtensions.data());

bool hasMSFTLayeredDriver = false;
for (const auto &extension : availableExtensions)
{
if (strcmp(extension.extensionName, VK_MSFT_LAYERED_DRIVER_EXTENSION_NAME) == 0)
{
hasMSFTLayeredDriver = true;
break;
}
}

VkPhysicalDeviceProperties2 deviceProperties2{};
deviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;

VkPhysicalDeviceLayeredDriverPropertiesMSFT layeredDriverProperties{};
layeredDriverProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LAYERED_DRIVER_PROPERTIES_MSFT;

if (deviceProperties.apiVersion >= VK_API_VERSION_1_1)
{
if (hasMSFTLayeredDriver)
deviceProperties2.pNext = &layeredDriverProperties;

vkGetPhysicalDeviceProperties2(device, &deviceProperties2);
}

int score = 2;

// optional

Expand All @@ -1656,6 +1686,10 @@ int Graphics::rateDeviceSuitability(VkPhysicalDevice device, bool querySwapChain
if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU)
score += 10;

// Reduce the score if this is something like Vulkan-on-D3D12 rather than a native driver.
if (hasMSFTLayeredDriver && layeredDriverProperties.underlyingAPI != VK_LAYERED_DRIVER_UNDERLYING_API_NONE_MSFT)
score /= 2;

// definitely needed

if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU)
Expand All @@ -1668,11 +1702,15 @@ int Graphics::rateDeviceSuitability(VkPhysicalDevice device, bool querySwapChain
if (!indices.isComplete() && (querySwapChain || !indices.graphicsFamily.hasValue))
score = 0;

bool extensionsSupported = checkDeviceExtensionSupport(device);
if (!extensionsSupported)
std::set<std::string> missingExtensions(deviceExtensions.begin(), deviceExtensions.end());

for (const auto &extension : availableExtensions)
missingExtensions.erase(extension.extensionName);

if (!missingExtensions.empty())
score = 0;

if (extensionsSupported && querySwapChain)
if (missingExtensions.empty() && querySwapChain)
{
auto swapChainSupport = querySwapChainSupport(device);
bool swapChainAdequate = !swapChainSupport.formats.empty() && !swapChainSupport.presentModes.empty();
Expand Down

0 comments on commit 0e5133e

Please sign in to comment.